If you execute:
System.out.println(someObj.toString());
you probably see the output like
someObjectClassname@hashcodenumber
My question : Is there any specific reason why hashCode number is displayed there?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The object hash code is the only standard identifier that might allow you to tell different arbitrary objects apart in Java. It’s not necessarily unique, but equal objects normally have the same hash code.
The default
toString()method shows the object class and its hash code so that you can hopefully tell different object instances apart. Since it is also used by default in error messages, this makes quite a bit of sense.See the description of the
hashCode()method for more information.