什么是“类型ArrayList不是通用的”意思? [英] What does "The type ArrayList is not generic" mean?

查看:291
本文介绍了什么是“类型ArrayList不是通用的”意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的新手并且正在尝试学习程序员可以使用的各种集合。我在Eclipse中的剪贴簿中导入了java.util并检查了以下代码。

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");

我收到此输出。

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

推荐答案

您在Eclipse中的Java版本设置为1.4,仅在Java中引入了泛型在Java 5中。

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

在eclipse中将JDK更改为1.5或更高,以解决此问题。

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

你可以通过项目 - >检查您的JDK Java构建路径 - >库

如果在这里您看到它是Java 1.5或更高版本,那么请检查编译器合规性是否设置为5及以上。

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

您可以检查项目 - > Java编译器

编辑:

向Eclipse添加新的jdk

To add new jdk to Eclipse

右键单击项目 - > Java构建路径 - >库 - >添加库 - > JRE系统库 - >已安装的库 - >添加 - >标准VM - >提供您的安装位置并按确定

请注意,在已安装的JRE列表中,请确保检查Java 7。

这篇关于什么是“类型ArrayList不是通用的”意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆