foreach输出问题
package com.imooc.collection; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class SetTest { public List<Course> coursesToSelect; public SetTest() { coursesToSelect = new ArrayList<Course>(); }
public void testForEach() {
System.out.println("有如下课程待选(通过for each访问):");
for (Object obj : coursesToSelect) {
Course cr = (Course) obj;
System.out.println("课程:" + cr.id + ":" + cr.name);
}
}
上面已经使用了Course泛型为什么下面Foreach的时候还要强制转换