Syntax error on ArrayList declaration

眉间皱痕 提交于 2020-01-05 05:22:05

问题


I've got the following code:

import java.util.*;

public class Group {
    public static void main(String[] args) {
    ArrayList<Integer> list = new ArrayList<Integer>();
    }
}

Eclipse (3.0.0) complains about the ArrayList declaration: syntax error on token "(", on both tokens "<", and then on token "=". I'm using java 1.5.0_07.

What am I doing wrong?

Thanks, regards, Miel.


回答1:


Set your JDK level to >= 5.0 to enable support for generics.

It's at Project -> Properties -> Java Compiler -> Compiler Compliance Level




回答2:


Your project is probably set to Java 1.4 target.




回答3:


Sounds like you've installed 1.5 on your box, but not in Eclipse. To fix that, go to Window->Preference->Installed JREs, and add your installed JRE.



来源:https://stackoverflow.com/questions/1290920/syntax-error-on-arraylist-declaration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!