11行目: 11行目:
         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;
    }   
}