This is regarding comparing object reference using ==
If we are comparing object references using == , then Both the operands should be type-compatible, that is it must be possible to cast one into the other's type, otherwise compile time error occurs.
( taken for Khalid. book )
Can someone explain this to me ?
Consider the code:
Integer i = new Integer(1);
Long l = new Long(1);
if( i == l)
...
String s = new String("an");
StringBuffer sb = new StringBuffer("an");
if( s == sb)
...
Both the above give compile time error.
Is it something to do with the peer classes( two classes at the
same level of hierarchy )or unrelated classes which cannot be compared ?
Can someone explain to me in better terms .
[This message has been edited by Angela Narain (edited August 30, 2001).]
[This message has been edited by Angela Narain (edited August 31, 2001).]