This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics Qs

 
Sonal Raje
Greenhorn
Posts: 13
  • 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
  • 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
  • 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: 15438
41
Android IntelliJ IDE Java Scala Spring
  • 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
  • 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
  • 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: 15438
41
Android IntelliJ IDE Java Scala Spring
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic