重複の可能性:
ハッシュコードと等号
hashcode私は、and equals とその関係について多くの記事を読みました。これまでのところ、私の理解では、デフォルトですべてobjectに equals とhashcodefunction があります.Javaclassにはこれらの関数があります。現在hashcodeは、オブジェクトのメモリ アドレスを返すことを意味します。hashcodesはデフォルトで一意です。オブジェクトが作成されると、一意の has コードが取得されます。
- ここで私の質問は、ルールに従って関数をオーバーライドする必要がある
override場合です..?equalshashcode hashcodeequals メソッドと一緒に関数を実装しますが、hascode実装は役に立ちません..?そして、 フレームワーク内およびフレームワークでどのように
hashcode使用されますか..?hashmaphashtablecollectionclass person{ string name; string employer; boolean equals(Object o){ person per=(person)o; if(per.employer==this.employeer){ return true } return false; } int hashcode(){ return 0;//what ever i do in hashcode does it really effect any thing..as the equals does //the comparison for me and gave me the result } }
およびでの のhascodes使用方法hashmaphashtable
ありがとう、