来看看这个令人奇怪的问题哦
package CourseToSelect;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ListTest {
List<Course> coursesToSelect ;
public ListTest(){
coursesToSelect = new ArrayList<Course>();
}
public void Add(){
Course cr1 = new Course("1","数据结构");
coursesToSelect.add(cr1);
Course temp;
Course course[] = {new Course("2","C语言"),new Course("3","高数") };
temp = (Course)coursesToSelect.get(0);
System.out.println("添加了课程:"+temp.ID+":"+temp.Name);;
}
public static void main(String[] args) {
ListTest lt = new ListTest();
//lt.Add();
Iterator<Course> it = lt.coursesToSelect.listIterator();
while(it.hasNext()){
Course temp = (Course)it.next();
System.out.println("添加了课程:"+temp.ID+":"+temp.Name); }
}
}
为什么运行不出结果呢?????真是令人疑惑