This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
this is a guess, but i assume when you call b1.toString(), it makes a temporary String object in memory. when you call it again, it makes ANOTHER temporary String object. they are different objects, so they are not == equal.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
It depends on what class b1 is and whether that class provides any guarantees about what its String method does. But in general, there are no guarantees about whether toString() will create a new String or reuse an existing one. You could look at the source code for b1's class to find out exactly what happens in this case, but usually this is just not very important. It's generally best to write code to se equals() rather than == when comparing Strings, and that way you won't be fooled by strange behavior like this.
"I'm not back." - Bill Harding, Twister
Joined: Jun 03, 2003
Sorry.... b1 is the following: Byte b1 = new Byte("127")