The reason is that the toString() method of Object class returns a new Object of the string representation of the object being passed as an argument.
Generally most classes overload this method as per their specific requirement. In the case of String class this is not
provided for, so the Object class's toString is called.
Actually, the String class
does provide its own toString() method. But that really doesn't have any bearing on the code in the original question.
The original code is using a Byte object. The Byte class also provides its own toString() method. Byte's toString() method returns a new String object when it's called, so by calling byte.toString() (in the original code) twice, returns 2 different String objects. And given the nature of the == operator, the code will print False.
Also, calling toString() will not put a String object into the String pool. You have to call intern() on that object to do that. Interestingly enough (and logically), if you run the following code, you get a printout of True.
[CODE]public class TestByteString
{
public static void main(String args[])
{
Byte b1 = new Byte("127");
if(b1.toString().intern() == b1.toString().intern())
System.out.println("True");
else
System.out.println("False");
}
}[\code]
April
[This message has been edited by April.Johnson (edited July 27, 2001).]