Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualWooh

Posted 24 May 2013 - 08:54 AM

By the way, is that Integer.toHexString(hashCode()) supposed to be the object's location in the heap?

No. Hash codes are normally meant to be used in hash tables and things like that. The hashCode() defined by Object might very well use the memory address but it's not guaranteed, and many classes overrides this method to return the same hash code for all objects that compares equal.

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.)


#1Wooh

Posted 24 May 2013 - 08:40 AM

By the way, is that Integer.toHexString(hashCode()) supposed to be the object's location in the heap?

No. Hash codes are normally meant to be used in hash tables and things like that. The hashCode() defined by Object might very well use the memory address but it's not guaranteed, and many classes overrides this method.

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.)


PARTNERS