import java.util.*;
public class myConnection {
public static void main(String args[]){
ArrayList mystr=new ArrayList();
mystr.add("一个字符串");
String str=(String)mystr.get(0);
System.out.println(str); //下面的代码对上边的程序做了调整,为什么就出错了呢?(上边代码是正常的!)
ArrayList<String> alist=new ArrayList<String>();
alist.add("一个字符串");
String aa=alist.get(0); //注意这里少了强类型转换。
System.out.println(aa);}
}出错如下:java.lang.Error: Unresolved compilation problems:
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 at com.paiao.bdpm.test.myConnection.main(myConnection.java:11)
Exception in thread "main"
public class myConnection {
public static void main(String args[]){
ArrayList mystr=new ArrayList();
mystr.add("一个字符串");
String str=(String)mystr.get(0);
System.out.println(str); //下面的代码对上边的程序做了调整,为什么就出错了呢?(上边代码是正常的!)
ArrayList<String> alist=new ArrayList<String>();
alist.add("一个字符串");
String aa=alist.get(0); //注意这里少了强类型转换。
System.out.println(aa);}
}出错如下:java.lang.Error: Unresolved compilation problems:
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 at com.paiao.bdpm.test.myConnection.main(myConnection.java:11)
Exception in thread "main"
解决方案 »
- ArrayList的问题
- 面试题
- showMessageDialog如何设置其显示的位置
- JMF包的问题
- 正则表达式初学者
- 为什么可以从String/StringBuffer读却不可以往String里写呢?
- 如何用java实现用8位二进制数表示一个字符?高手帮忙!
- 经过这几天的观察,我觉得一个midlet里应该有如下这么几个线程,它和application是不一样的
- 关于JApplet
- 运行时异常如何使用log4j进行管理
- 连接池乱码。。。。。。。。。修改总是失败阿
- 如果参数不在表格的第一列,就会出现该列之前的字段显示上一行颜色,还有选择这一行时,该列字段不显示选择行的颜色,而是现实设定的颜色
if you wanna use the generic,,try to change the ArrayList to the Vector or Array
把“源级别”设定为5.0;不太明白你的意思,能具体解释一下吗?什么叫"源级别"?
如果是eclipse的话,在window-->preferences-->java->complier-->complier compliance level:选择5.0就可以了
在“Preferences”属性窗口中选择"java" - "Compiler"
然后把“Compile compliance level”设置为5.0。