[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

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?

0
rnicholus
Asked:
rnicholus
  • 4
  • 3
1 Solution
 
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
 
RomanRegaCommented:
Nothing to care about. It's just the reference number of your object.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now