Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from element type Object to Data
at Test.main(Test.java:17)
-------------------------------------------------
import java.util.ArrayList;
class Data {
int val;
}
public class Test {
public static void main(String args[]) {
Data data = new Data();
ArrayList list = new ArrayList();
for (int i = 100; i < 103; i++) {
data.val = i;
list.add(data);
}
就是这里报错-----> for (Data d : list) {
System.out.println(d.val);
}
}
}
|