Don't tell me there is nothing beyond sky, There are footprints on moon.
Originally posted by Gaurav Chauhan:
But today when i created a reference of String class and tried printing the same i got the value as output not the Address.
Don't tell me there is nothing beyond sky, There are footprints on moon.
Originally posted by Gaurav Chauhan:
Will you please tell me the name of any class that does it ?
Originally posted by Gaurav Chauhan:
When i tried to look at the definition of hashCode() method, i didn't got any it is native ?
Originally posted by Gaurav Chauhan:
...it doesn't serves my purpose.
The toString() method of String class just returns the reference of String Class so i must get the reference id as output. But i am not getting it, i get the value.
Originally posted by Ernest Friedman-Hill:
Many, many classes override hashCode(). Since you're already looking at the source for java.lang.String, I'm surprised you didn't notice that String does so.
Anyway, you're thinking much too hard here. toString() returns a String, right? And so String::toString() returns itself. Whenever you print an object, toString() is called to return a printable String. String::toString() just happens to have a handy one available already!
First question, when has Java ever give you a "reference id" when you return an reference of String class? Second question, what the heck is a "reference id"?
Henry
Don't tell me there is nothing beyond sky, There are footprints on moon.
Originally posted by Gaurav Chauhan:
Java has never given me the reference-id for String Class and this is my question.
Reference-id: It is a unique number assigned to objects. http://www.nomachetejuggling.com/2008/06/04/getting-a-java-objects-reference-id/
Don't tell me there is nothing beyond sky, There are footprints on moon.
One more thing that i proved here is that String objects are immutable. In above case first 2 values of "sob" are same so their hashcode is same too but third value is different so a different memory location has been assigned to it.
Don't tell me there is nothing beyond sky, There are footprints on moon.