日期:2014-05-20  浏览次数:20731 次

此数组是啥意思?谢
private   ArrayList <Ball>   balls   =new   ArrayList <Ball> ();
其中的Ball   是另外定义的一个public类。

一般遇到的数组没有这样定义过。
这样定义还是第一次遇到
麻烦谁告知一声。
谢谢

------解决方案--------------------
这个是JDK 1.5 的新特性。举个例子。 一个列表中加入3个数字,然后从列表中取出作合计的操作。

JDK 1.4 的时候
List testList = new ArrayList();
testList.add(new Integer(100));
testList.add(new Integer(200));
testList.add(new Integer(300));
int result = 0;
for(int i = 0; i < testList.size(); i ++) {
// 这里从列表中取数据时,需要强制转换。
result += (Integer)testList.get(i).intValue();
}
System.out.println(result);


JDK 1.5 的时候
List <Integer> testList = new ArrayList <Integer> ();
// 注意,JDK1.5的 int 的 100,能够自动的转换成 Integer 类型。不强制要求 new Integer(100)
testList.add(100);
testList.add(200);
testList.add(300);
int result = 0;
for(int i = 0; i < testList.size(); i ++) {
// 这里从列表中取数据时,不需要强制转换。
result += testList.get(i).intValue();
}
System.out.println(result);


PS. 以上代码没有编译运行测试过,仅仅用于说明。