求大神?。。。?!
誰(shuí)知道 Course類的id 跟 name進(jìn)行封裝后 怎么把 gatId? gatName 的值傳入保存到 coursesToSelect中?
誰(shuí)知道 Course類的id 跟 name進(jìn)行封裝后 怎么把 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();
? ? ? ?}
? ?}
說(shuō)錯(cuò)了 是setid 跟setname的值
舉報(bào)
2017-12-27
封裝方式的已經(jīng)自己解決了 大家可以參考? 有好的方式留言