I read in a book that hashCode () shows a region of memory that helps (for example, HashSets) find the corresponding objects in memory. But how can this be true if we cannot directly manipulate memory in Java? There are no pointers, in addition, objects are created and moved from one place to another, and the developer does not know about it.
I read that an implementation like hashCode () {return 42;} is terrible and terrible, but what's the difference if we cannot instruct the VM on where to place our objects?
The question is, what is the purpose of hashCode () at a deep level if we cannot manipulate memory?
Jon Skeet (+1), , -. - - , , - , , . , , , , -, - - , . - , , , , , ( return 42;), , , .
return 42;
# hashCode - , , , , . -, , String BigDecimal, , . , , , .
, hashCode() , (, HashSets) .
, hashCode. . .
hashCode
, - HashMap, , . , - , -. ( ) - .
HashMap
. -.
- - "". ", ", "MyClass obj = new MyClass()" , "obj" .
, - Java()?
:
K & B , hashcode():equals (Object), hashCode() .equals (Object), hashcode().hashcode() , ().
K & B , hashcode():
equals (Object), hashCode() .
equals (Object), hashcode().
hashcode() , ().
- - , . - , .
, hashmaps, , - , " " ( ) .
, ( -, , , ). wikipedia hashmap entry
HashCode - , java , , , . (SortedSet )
.
, , . , Object hashCode(), , .
, hashCode, class Object . ( , JavaTM.