关于eclipse编写java代码时不能运行for-each语句的问题

来源:互联网 发布:小米擦除数据后怎样 编辑:程序博客网 时间:2024/04/29 19:53
     在Java1.5时加入了for-each语句,其语法为for (variable : collection) statement。比如在代码中
写如下语句:
for (int element : a)
   System.out.println(element);
在上面的语句在Eclipse中会出现编译错误。原因是在Eclipse中Java默认的版本为1.4,只要将其版本号改为1.5或更高版本。在Java的project上点右键属性(properties)。Java compiler->compiler compliance level->6.0(或5.0)。如不能更改,在Enable project specific settings前选中前面的CheckBox即可。