編集の要約なし
 
(同じ利用者による、間の1版が非表示)
7行目: 7行目:
     String name;
     String name;
     int hp;  
     int hp;  
 
     public int hashCode() {
     public int hashCode() {
         int result = 37;  
         int result = 37;  
         result = result * 31 + name.hashCode();
         result = result * 31 + name.hashCode();
         result = result * 31 + this.hp;
         result = result * 31 + hp.hashCode();
         return result;
         return result;
     }   
     }   
  }
  }

2019年6月20日 (木) 23:57時点における最新版

Object. hashCode [1]

オブジェクトのハッシュ・コード値を知らせます。

オーバーライドの定石

class Hero {
    String name;
    int hp; 

    public int hashCode() {
        int result = 37; 
        result = result * 31 + name.hashCode();
        result = result * 31 + hp.hashCode();
        return result;
    }   
}