import java.util.ArrayList;
class Data {
int val;
}
public class Test {
public static void main(String args[]) {
Data data = new Data();
ArrayList<Data> list = new ArrayList<Data>();
for (int i = 100; i < 103; i++) {
data.val = i;
list.add(data);
}
for (Data d : list) {
System.out.println(d.val);
}
}
}
这个程序为何最后输出的是102,102,102,而不是100,101,102,!
还请各位大神指点迷津!
|