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"

解决方案 »

  1.   

    the error had tell you "The type ArrayList is not generic"
    if you wanna use the generic,,try to change the ArrayList to the Vector or Array
      

  2.   

    我用的IDE 是myeclipse5.0,和这个有关系吗?
      

  3.   

    trumplet(检查):
    把“源级别”设定为5.0;不太明白你的意思,能具体解释一下吗?什么叫"源级别"?
      

  4.   

    就是将编译器的编译级别选择为5.0,范型是5.0的新特性
    如果是eclipse的话,在window-->preferences-->java->complier-->complier compliance level:选择5.0就可以了
      

  5.   

    就是说,把你的Eclipse的编译级别设置为5.0。[Window] - [Preferences]
    在“Preferences”属性窗口中选择"java" - "Compiler"
    然后把“Compile compliance level”设置为5.0。