I'm curious why Object.toString()
returns this:
return getClass().getName() + "@" + Integer.toHexString(hashCode());
as opposed to this:
return getClass().getName() + "@" + hashCode();
What benefits does displaying the hash code as a hex rather than a decimal buy you?
Object.hashCode
used to be computed based on a memory location where the object is located. Memory locations are almost universally displayed as hexadecimal.
The default return value of toString
isn’t so much interested in the hash code but rather in a way to uniquely identify the object for the purpose of debugging, and the hash code serve well for the purpose of identification (in fact, the combination of class name + memory address is truly unique; and while a hash code isn’t guaranteed to be unique, it often comes close).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With