File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics Qs

 
Sonal Raje
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1862
Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not getting any error. what is your Java version?
 
Sonal Raje
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic