Unless specific code, you should not use this method but
use hash
instead.
As its name hints it, the internal hash code, is used internally
to provide a hash value.
It is also used by the inspect
method to loosely identify objects
and helps debugging.
var a = "Hello"
var b = a
assert a.object_id == b.object_id
The specific details of the internal hash code it let to the specific engine. The rules are the following:
object_id
MUST be invariant for the whole life of the object.object_id
.object_id
.object_id
of a garbage-collected instance MIGHT be reused by new instances.object_id
of an object MIGHT be non constant across different executions.For instance, the nitc
compiler uses the address of the object in memory
as its object_id
.
TODO rename in something like internal_hash_code
# An internal hash code for the object based on its identity.
#
# Unless specific code, you should not use this method but
# use `hash` instead.
#
# As its name hints it, the internal hash code, is used internally
# to provide a hash value.
# It is also used by the `inspect` method to loosely identify objects
# and helps debugging.
#
# ~~~
# var a = "Hello"
# var b = a
# assert a.object_id == b.object_id
# ~~~
#
# The specific details of the internal hash code it let to the specific
# engine. The rules are the following:
#
# * The `object_id` MUST be invariant for the whole life of the object.
# * Two living instances of the same classes SHOULD NOT share the same `object_id`.
# * Two instances of different classes MIGHT share the same `object_id`.
# * The `object_id` of a garbage-collected instance MIGHT be reused by new instances.
# * The `object_id` of an object MIGHT be non constant across different executions.
#
# For instance, the `nitc` compiler uses the address of the object in memory
# as its `object_id`.
#
# TODO rename in something like `internal_hash_code`
fun object_id: Int is intern
lib/core/kernel.nit:63,2--92,29