<< 2009/07/05 | Home | 2009/07/07 >>
PR: 転職    お墓    エコ    通販    結婚相談所    シルバー    質屋    葬式    漫画    エステサロン   

System.identityHashCode()って、一意である保証は無いのね。

Object.hashCode()のAPIドキュメントを見ていたら、

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

ん〜、結構これ使って、キャッシュとか実装した記憶が(汗)。まぁ、32bit JVMならまず大丈夫そうだけど。

となると、オブジェクトの参照を見分けるには、まず、System.identityHashCode()で分けておいて、この値が同じものを、Listにでも保存して、==で線形に比較するしかないんだろうか。

このサイトの掲載内容は私自身の見解であり、必ずしもIBMの立場、戦略、意見を代表するものではありません。
日本アイ・ビー・エム 花井 志生 Since 1997.6.8