Difference between hash code and link or object address?

difference between hash code and object link or address?

+4
source share
3 answers

In JavaME, these three things are not related.

The hashCode object is a semi-unique identifier for it.

An object reference is a processed object on this object.

The object address (possibly) is unavailable and, of course, useless.

+4
source

The address / link to the object indicates the location in memory in which the object is located.

The hash code is generated using the hash algorithm and is used to identify objects in the collection of hashes. Different algorithms will generate different codes (bad algorithms will lead to the appearance of weak hash codes and more collisions in the collection).

0
source

The hash code of the object and its address in memory are not related in any way. It is simple that various implementations of objects (in different languages, actually) use the memory address of the object as a unique way of identifying this object.

In general, a pair of hashCode and equals methods provide a means to compare objects for identification. When implementing your own hash scheme, you should keep in mind that the hash value must consist of something that makes the object unique. For example, imagine that you provide a mapper object to a database system and want to present a Customer object - you know that in your table clients are unique with respect to their primary key, so returning this primary key as a hash code will be perfectly acceptable and in no way not associated with the memory address of the object.

If the client is identified using his first name, last name and date of birth (which is really not enough to uniquely identify the person, but let him be simple for brevity), you can use these 3 values ​​in the code hash and use it in the implementation of O / R matching.

0
source

All Articles