foreach问题
// 預設10個元素
SafeArray arr1 = new SafeArray();
// 指定配置20個元素
SafeArray arr2 = new SafeArray(20);
for(int i = 0; i < arr1.getLength(); i++)
arr1.setElement(i, (i+1)*10);
for(int i = 0; i < arr2.getLength(); i++)
arr2.setElement(i, (i+1)*10);
for(int element : arr1.getArray())
System.out.print(element + " ");
System.out.println();
for(int element : arr2.getArray())
System.out.print(element + " ");
System.out.println();
执行时提示这个错误,JDK是1.6的,请问为什么?
Exception in thread "main " java.lang.Error: Unresolved compilation problems:
Syntax error, 'for each ' statements are only available if source level is 5.0
Syntax error, 'for each ' statements are only available if source level is 5.0
at JavaTest.main(JavaTest.java:16)
[解决办法]
jdk版本的问题啊
[解决办法]
for each 语句只在5.0的jdk下有效