求大神!!!!!
谁知道 Course类的id 跟 name进行封装后 怎么把 gatId gatName 的值传入保存到 coursesToSelect中
谁知道 Course类的id 跟 name进行封装后 怎么把 gatId gatName 的值传入保存到 coursesToSelect中
2017-12-27
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class listText{
public List coursesToSelect;
public listText(){
this.coursesToSelect= new ArrayList();
}
public void testAdd(){
Course t=new Course();
String b;
t.setId("fsdfs") ;
t.setName("dsff");
coursesToSelect.add(t);
Course temp =(Course)coursesToSelect.get(0);
System.out.println("add"+temp.getId()+"add"+temp.getName());
}
public static void main (String[] args){
listText t= new listText();
t.testAdd();
}
}
class Course{
private String id;
private String name;
// public Course(String id, String name) {
// this.id=id;
// this.name=name;
// }
public void setId(String newId){
id=newId;
}
public String getId(){
return id;
}
public void setName(String newName){
name=newName;
}
public String getName(){
return name;
}
}
class student{
public String id;
public String name;
public Set Coursee;
public student(String id,String name){
this.id=id;
this.name=name;
this.Coursee=new HashSet();
}
}
举报