import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 备选课程类
*/
public class ListTest {
public List coursesToSelect;
public ListTest() {
this.coursesToSelect = new ArrayList();
}
/**
*/
public void testAdd(){
Courses cr1 = new Courses("1","数据结构") ;
coursesToSelect.add(cr1);
Courses temp = (Courses) coursesToSelect.get(0);
System.out.println("添加了课程:" +temp.id +":"+ temp.name );
Courses cr2 = new Courses("王泽宇","健身只打卡");
coursesToSelect.add(0,cr2);
Courses temp2 = (Courses) coursesToSelect.get(0);
System.out.println("添加了课程:" +temp2.id +":"+ temp2.name );
Courses[]course = {new Courses("3","java" ),new Courses("4","汇编语言")};
coursesToSelect.addAll(Arrays.asList(course));
Courses temp3 = (Courses)coursesToSelect.get(2);
Courses temp4 = (Courses)coursesToSelect.get(3);
System.out.println("添加了两门课程:" + temp3.id+ ":"+temp3.name +";" + temp4.id+":"+temp4.name);
ListTest lt = new ListTest();
lt.testAdd();
}
public static void main(String[] args) {
ListTest lt = new ListTest();
lt.testAdd();
}
}
出现死循环了