A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
equals() method - comparing Objects
Joined: Jul 27, 2005
Jul 27, 2005 04:53:00
I'm studying for the
1.5 exam by reading the K&B book and some additional stuff (Sun's JDK 1.5 tutorials + other things).
I'm a bit confused over a statement in the K&B book - page 389 - "Wrappers won't pass equals() if they're in different classes"
...does this also means (like the == operator), that my own objects will fail the
or does this only apply to Wrappers?
Can somebody help on this?
Joined: Jul 11, 2003
Jul 27, 2005 05:20:00
"Wrappers won't pass equals() if they're in different classes"
This statement is explained with a code example on page 384 of K&B.
Here is another example:
Integer a = new Integer(2); Long b = new Long(2); System.out.println(a.equals(b)); // false because of different classes Integer c = new Integer(2); System.out.println(a.equals(c)); // true because of same classes and value
[ July 27, 2005: Message edited by: Joyce Lee ]
I agree. Here's the link:
subject: equals() method - comparing Objects
SCJP 5 Features
Question on : Integer value comparision
query in answer
SCJP 5.0 preparationK &B
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013