为了账号安全,请及时绑定邮箱和手机立即绑定

this.courses = new HashSet<Course>(); 这句不理解呀

public class Student {


public String id;

public String name;

public Set<Course> courses;


public Student(String id, String name) {

this.id = id;

this.name = name;

this.courses = new HashSet<Course>();

}

}



正在回答

2 回答

第三行声明了courses是Set接口泛型为Course的引用

this.courses = new HashSet<Course>();

this表示当前类,this.courses即当前类的courses属性  

new HashSet<Course>() 实例化一个HashSet类型的对象,HashSet是Set接口的一个实现类

大概就是这样


0 回复 有任何疑惑可以回复我~
#1

积蓄_TNT 提问者

非常感谢!
2016-03-15 回复 有任何疑惑可以回复我~

为代码第三行的Courses变量,进行创建 

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

this.courses = new HashSet<Course>(); 这句不理解呀

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号