I can get the unique id like className@2345 of my object by calling its toString() method, but after I overwrite the toString() method, how can I get that unique id?
views:
173answers:
3
+12
A:
You can call System.identityHashCode() and pass your object as parameter, then you will get it.
Rose
2009-07-17 01:24:08
A:
If you are looking for a one line toString() implementation that will also print the className@address, check out Apache Commons ToStringBuilder.reflectionToString(). This will return a String in the format: className@address[field1=value1, field2=value2, ...]
0sumgain
2009-07-17 03:05:59
It's not an address but a hash code.
joeslice
2009-07-17 03:09:57