6-1節關于重寫equals方法的問題
對于Course的方法我沒有使用視頻講解的方法,而是采用了正常的get/set方法,但是在測試List的那節重寫equals方法中做第四個if的判斷時候,使用this關鍵字并不能夠像之前調用course的對象方法那樣出來getName(),我該如何解決?
public?class?Course?{
????private?String?id;
????private?String?name;
????public?Course(String?id,?String?name)?{
????????this.id?=?id;
????????this.name?=?name;
????}
????public?Course()?{
????}
????public?String?getName()?{
????????return?name;
????}
????public?void?setName(String?name)?{
????????this.name?=?name;
????}
????public?String?getId()?{
????????return?id;
????}
????public?void?setId(String?id)?{
????????this.id?=?id;
????}
}public?boolean?equals(Object?object){
????if(this==object){
????????return?true;
????}
????if(object==null){
????????return?false;
????}
????if(!(object?instanceof?Course)){
????????return?false;
????}
????Course?course=?(Course)?object;
????if(this.)//這里沒有提示getName()只有getClass()但是二者無論是自己寫上還是選中都會出現紅色的波浪線有錯誤
????return?true;
}
2018-06-24
你不是在這個當前Course.java下寫的嗎? private的屬性可以在類中使用,建議看一下java訪問修飾符這一章節~