aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Qs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics Qs" Watch "Generics Qs" New topic
Author

Generics Qs

Sonal Raje
Greenhorn

Joined: Jun 02, 2008
Posts: 13
import java.util.*;
public class GenericsPractice {
public static void main(String[] args) {
List<Apple> l1= new ArrayList<Apple>();
}
}
class Apple
{
public void color(){
System.out.println("Apple Color");
}
}
When I compile this code I get the following error at line 3 ,"the class List is not generic ,it cannot be parametrised with with arguments "apple".
Can anyone explain this please..?
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

I am not getting any error. what is your Java version?


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Sonal Raje
Greenhorn

Joined: Jun 02, 2008
Posts: 13
I have java compiler 5.0.
But the jre for 5.0 is not there.Is it causing the error at complie time?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

If you have JDK 5.0 installed, then you also have JRE 5.0 (because it's included with the JDK).

Your code compiles without any problems using the Java 5.0 compiler. Can you copy & paste the exact error message that you get?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

are you using any IDE or running from command line? That case try java -version to get the details. It will work fine with JDK 5.0.
Sonal Raje
Greenhorn

Joined: Jun 02, 2008
Posts: 13
I am working with eclipse 3.2.2 . I tried to change compiler to jdk1.5 by doing this--
Project->properties->java compiler-> jdk compliance levels(changed it to to 5.0) Which are the jars that need to be addded to java Build Path?
The exact error that I get is "The type list is not generic .It cannot be paraetrised with argument Apple".
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

In Eclipse, right-click your project and select Properties. Then go to Java Build Path, select the tab Libraries. Remove the JRE System Library of Java 1.4 (or whatever is there); then click "Add Library", select "JRE System Library" and follow the wizard to select the Java 5 JRE system library.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics Qs