John Hoffman John Hoffman - 7 months ago 50
Java Question

What does "The type ArrayList is not generic" mean?

I am new to Java and trying to learn the various collections that programmers can use. I imported "java.util" into a scrapbook in Eclipse and inspected the following code.

ArrayList<String> list = new ArrayList<String>();
list.add("test1");
list.add("test2");


I receive this output.

The type ArrayList is not generic; it cannot be parameterized with arguments <String>
Syntax error, parameterized types are only available if source level is 5.0
The type ArrayList is not generic; it cannot be parameterized with arguments <String>
Syntax error, parameterized types are only available if source level is 5.0


What does this error mean? I did not make a generic array list; I made an array list of strings. Furthermore, what is "source level"?

Answer

Your Java version in Eclipse is set to 1.4, generics in java were introduced only in Java 5.

Change your JDK to 1.5 or above in eclipse that will resolve this issue.

You can check your JDK by Project - > Java Build Path - > Libraries

If here you see it being Java 1.5 or above then check the compiler Compliance is set to 5 and above.

You can check that Project - > Java Compiler

EDIT:

To add new jdk to Eclipse

Right click on Project - > Java Build Path - > Libraries - > Add Libraries - > JRE System Library - > Installed Libraries - > Add - > Standard VM - > Provide your installation location and press OK

Note in the list of Installed JRE, ensure that you check your Java 7.

Comments