报string异常
public void testGet() {
int size = coursesToSelect.size();
System.out.println("有如下课程待选:");
for(int i= 0 ; i < size; i++) {
Course cr=(Course)coursesToSelect.get(i);
System.out.println("课程:" + cr.id + ":" + cr.name);
}
}
private void testForEach() {
System.out.println("有如下课程待选(通过for each访问):");
Course course=new Course();
for (Object obj : coursesToSelect) {
Course cr =(Course) obj;
System.out.println("课程:" + cr.id + ":" + cr.name);
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to com.imooc.collection.Course
at com.imooc.collection.ListTest.testGet(ListTest.java:127)
at com.imooc.collection.ListTest.main(ListTest.java:118)