Setter-Getter数组
有人能帮我解决一个小问题吗。例如,我想为一个学生设置3节课,但当我尝试这一点时,我无法设置课
student.setStudentLecture(lecture);
student.setStudentLecture(lecture1);
public class Student {
private Lecture[] lecture;
public void setStudentLecture(Lecture[] lecture) {
this.lecture = lecture;
}
public Lecture[] getStudentLecture() {
return lecture;
}
}
# 1 楼答案
由于setter也是数组,所以可以创建讲座数组并将其设置为Student
样本:-
还有student讲师作为数组,那么为什么要两次分配不同的数组,你可以组合两个数组并分配它
# 2 楼答案
您正在使用讲座对象数组,并使用两个不同的数组引用覆盖同一个数组。因此,它不起作用。使用以下代码: