These posts are confusing variables and Objects. Remember that variables are either primitives (ints etc, not Objects) or reference variables (contain a reference to an Object); a variable is NOT an Object.
Object's toString() is not defined to return anything related to the address of the object, nor does it return anything related to a reference. The API doc is perfectly clear - it returns the class name and the objects hash code.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
The hashCode() method
may return something relating to the address, but it's not guaranteed
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.)
Having said all that, there is nothing in the Java language that corresponds to a memory address, and there is no syntax for accessing memory addresses.
Reputation Points: 1924
Solved Threads: 952
Posting Expert
Offline 5,788 posts
since Apr 2008