Why Generics not working in my machine. Why below code not working in Eclipse without Type casting to the String
. I am using Java 1.6
package com.wi
This works without cast since Java 1.5.
package java.util;
public interface List<E> extends Collection<E> {
....
E get(int index);
....
}
Maybe useful: Java Generics
This statement can't give any error if you are using java 1.5 or greater. But if you are using some older version than
List<String> list = new ArrayList<String>();
will give error. First you will have to solve this issue than type cast will come.
Write an ENTIRE PROGRAM that has in it the lines you've posted above. Do NOT copy-and-paste them, type them all in. Include lines necessary for a java program, i.e. public static void main (String[] args)
etc. Do a 'clean' and 'build' on that program, and tell us the entire result. If that's still causes an error, post the entire program and the entire error.
Also be aware that it is difficult (at best) to figure out what's wrong with another machine's configuration without being able to look at it; help us get information about what's there. Abrupt answers make it appear that it is really Java you want us to fix.
have you checked the JVM configured in your eclipse project? Go to configure build path and then check if the correct libraries are included
In eclipse, go to Window > Preferences > Java > Compiler and look up JDK compliance. Make sure it's at least 1.5.