为什么我的temp.id输出值是null呢?
public void testAdd() {//创建一个课程对象,并通过调用add方法,添加到备选课程List中 Course cr1=new Course("1","数据结构"); courseToSelect.add(cr1); System.out.println("添加到备选课程"); Course temp=(Course)courseToSelect.get(0); System.out.println("添加了课程:"+temp.id+temp.name); Course cr2=new Course("2","C语言"); courseToSelect.add(0, cr2); Course temp2=(Course)courseToSelect.get(0); System.out.print("添加了课程:"+temp2.id+temp2.name); courseToSelect.add(cr1); System.out.println("添加到备选课程"); Course temp0=(Course)courseToSelect.get(2); System.out.println("添加了课程:"+temp0.name); //以下方法会抛出数组下标越界异常 // Course cr3=new Course("3","test"); // courseToSelect.add(4,cr3); Course[] course={new Course("3","离散数学"),new Course("4","汇编语言")}; courseToSelect.addAll(Arrays.asList(course)); Course temp3=(Course)courseToSelect.get(2); Course temp4=(Course)courseToSelect.get(3); System.out.println("添加了两门课程:"+temp3.id+":"+ temp3.name+":"+temp4.id+":"+temp4.name); Course[] course2={new Course("5","高等数学"),new Course("6","大学英语")}; courseToSelect.addAll(2, Arrays.asList(course2)); Course temp5=(Course)courseToSelect.get(2); Course temp6=(Course)courseToSelect.get(3); System.out.println("添加了两门课程"+temp5.id+":"+ temp5.name+":"+temp6.id+":"+temp6.name);}
为什么我的temp.id输出值是null呢?(testAdd方法已贴)