简体   繁体   中英

using 1.7.0_51 but Syntax error, 'for each' statements are only available if source level is 1.5

String[] str ={"a", "b","c", "d"};
for (String lists : str)
{
System.out.println(lists);
}

in above code while compiling i am getting error like this

ERROR in CollectionList.java (at line 19)
for (String lists : str)
     ^^^^^^^^^^^^^^^^^^
Syntax error, 'for each' statements are only available if source level is 1.5

kindly help me out this problem i am using java 1.7.0_51 version, OS linux Deepin

Thanks in advance

You need to tell javac which version of java you are using. This is done with the -source and -target parameters. If you are using Maven this can be set in your pom.xml with the compiler plug-in if you're using Ant this can be set in the javac Task.

您可以使用-source手动设置源版本兼容性

javac -source 5 YourFile.java
javac -source 7 YourFile.java

将是这个问题的解决方案

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM