Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wrapper class?

 
srikanth reddy
Ranch Hand
Posts: 252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

here the Output iam getting is "b1.toString()"...here we have only one reference value ..what are we doing here by calling toString method...
can anyone help me???

thanks

srikanth
[ September 28, 2005: Message edited by: Michael Ernest ]
 
Lalitha Gottumukkula
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think if(b1.toString() == b1.toString()) is trying to compare two different String objects, not their values. b1.toString() returns a string equivalent of object b1.

Try to use if(b1.toString().equals(b1.toString()). This will compare values in the objects.
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this will help:

Regards,
 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here on calling b.toString() in b1.toString() == b1.toString() we get two different String object because call to toString() is
done at run time.so == should result in false.Please correct me iff i am wrong
[ September 28, 2005: Message edited by: agrah upadhyay ]
 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haa Haa Haa
With above posting i have completed my 101 posts
 
Arvind Giri
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes! you are using only one reference b;
However keep in mind b.toString() returns a new String object, everytime it has been called.
That is why the actual checking here is between the reference returned by two b.toString(), which are different.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic