Class class toString method

I noticed that calling the overridden toString on a class (this) constructs a String similar to:

"ClassName@1cb25f1"

My question is, what is the data provided after the "@" sign in the returned String?  What does it repsent?  What would cause this portion of the String to change?

rnicholusAsked:
Who is Participating?
 
aozarovCommented:
read the javadoc for the default implementation of hashCode: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#hashCode()
0
 
aozarovCommented:
This a memory reference value "1cb25f1".
calling toString on an object (without overriding it) will give a unique value for each instance.
0
 
aozarovCommented:
Read http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#toString()
which provides the default implementation for toString
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
RomanRegaCommented:
Nothing to care about. It's just the reference number of your object.
0
 
rnicholusAuthor Commented:
Actually, according to the API, it is a hashcode, which, I beleive (correct me if I'm wrong) will only change if the object itself changes.  My new question is, now, is this hashcode generated based simply on method signatures and class variable signatures, or will the hashcode change if a single character, say, inside of a method changes?
0
 
rnicholusAuthor Commented:
Actually, I do care about this number.  I'm seeing if I can use it to uniquely identify a class.  I need to know, however, how this number is exactly generated.  Such as how closely related the number is to the implementation of the class.
0
 
rnicholusAuthor Commented:
Thank you, once again aozarov (you have answered at least one of my other questions).  I used to examine API's before asking questions, but I've been lazy lately.  I'll try to correct that.

To sum up my conclusion, the string returned by an Object's toString method is not guaranteed to be the same from one execution to another, so it should not be used to uniquely identify an implementation of an object.
0
 
aozarovCommented:
>>  not guaranteed to be the same from one execution to another, so it should not be used to uniquely identify an implementation of an object.
Correct. :-)
Have a look at Jakarta Commons lang project http://jakarta.apache.org/commons/lang/ which can assist you with a toString generation.
http://dev2dev.bea.com/lpt/a/406
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.