System.out.println (bs.equals (new String ("OK"))); } }
1. If you pass a String object then str.equals(obj) will be true if and only if in the above quote you write "OK". 2. Also u can pass only a String object to make the line str.equals(obj) work, passing a BetterString will always return false
He's calling the equals() method on the String object. So passing anything other than a String reference, it will return false.
What you are doing is passing the BetterString object to BetterString's over-ridden equals() method. What Keith Lynn is saying that passing BetterString object to String's equals() method will always return false.
Joined: Feb 07, 2005
That is a different situation.
The reason that works is because of this statement.
The condition in the else if will only be checked if you send a String object to the equals method.
But that is not the purpose of the equals method of BetterString.
The intention is to determine when one BetterString object is equal to another.
bs.equals(bs) only returns true because of this.
which does not test the contents of the BetterString object. [ July 12, 2006: Message edited by: Keith Lynn ]