对于Java来说我是一个相对较新的人,当我在任何地方都没有使用“静态”时,我不明白为什么setter方法是静态上下文。
public class Appointment {
LocalDateTime Time;
Doctor Doctor;
Patient Patient;
String Notes;
public Appointment(LocalDateTime time, Doctor doc, Patient pat, String notes){
Time = time;
Doctor = doc;
Patient = pat;
Notes = notes;
}
public void setNotes(String Notes) {
Appointment.Notes = Notes;
}
}
编辑:有人评论了这个答案,所以我无法将其标记为正确,但我将约会指定为注释。注释
答案 0 :(得分:4)
这是分配静态变量(不一定是当前类的成员)的语法。
public class Appointment {
Appointment.Notes = Notes;
代替写:
this.Notes = Notes;
或者更好地将变量名更改为标准名称:
this.notes = notes;
我强烈建议您遵守命名约定。在问题中引用实际的编译器错误消息也很有用。