it claimed implementation of object.hashcode()
(the default implementation objects) gives memory address of object. claim attached explanation of peculiar output produced object.to string().
see here example.
this not case jvms/jres aware of. not least because addresses 64 bits long now. also, garbage collectors relocate objects, address changes. i've seen claims can initial memory address of object. many objects have similar addresses, poor choice hash code.
are there, or have there ever been, used jvms/jres (initial) memory address of object.
i aware javadoc object
class suggests hashcode
implementation might memory address. suspect grossly out of date statement has never been updated.
indeed, current oracle jvm not use memory address (but can configured so):
https://stackoverflow.com/a/16105878/545127
the idea hashcode memory address historical artefact:
https://stackoverflow.com/a/13860488/545127
my question whether (and which) any used jvm used memory address (default) implementation.
since default hash code of object not need unique, returning whole address not necessary. implementation grab group of bits address - say, bits 3 through 35 on 64-bit system, or xor between upper 32 bits , lower 32 bits, or lower 32 bits.
but many objects have similar addresses [due garbage collection], poor choice hash code.
hash codes numerically close each other ok. small number of identical hash codes not create problem, because equality used resolve ties. situations when default hash code implementation used limited, because objects used keys in hash-based containers expected provide "good" implementations of hashcode
method.
oracle says default implementation of jvm uses internal address of object, whatever means, compute hashcode
. however, other jvm implementations not required same:
here quote oracle's documentation:
as reasonably practical,
hashcode
method defined classobject
return distinct integers distinct objects. (this typically implemented converting internal address of object integer, implementation technique not required java™ programming language.)
you can find actual implementation of algorithm here. search get_next_hash
function details. appears computing hash based on address done simple conversion:
value = intptr_t(obj) ;
Comments
Post a Comment