Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

java - 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"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...