About Question enthuware.ocajp.i.v8.2.1104 :
Posted: Mon Dec 19, 2016 12:24 am
The answer to this question seems to be in contradiction with a a previous question from Ethuware (ocajp.i.v8.2,1369). In that question,
The answer states that output to and are both false. And the explanation says thatshouldn't or both return false? Because they are all pointing to objects of different data types?
Code: Select all
Integer i1=1;
Byte b1 = 1;
Long g1= 1L;
Code: Select all
i1.equals(g1)
Code: Select all
i1.equals(b1)
If this is the case, in this question,The equals method of all wrapper classes first checks if the two objects are of the same class or not. If not, they immediately return false.
Code: Select all
Integer i = new Integer(42);
Long ln = new Long(42);
Double d = new Double (42.0);
Code: Select all
i.equals(d);
Code: Select all
d.equals(ln)