• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics Qs

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..?
 
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic