Topic:
integer i =
42
long l = 42l;
double d =
42.0
|
The following is true
A. (i = = L)
B. (i = = d)
C. (L = = d)
D.i.equals (d)
E.d.equals (L)
F.i.equals (L)
G.l.equals (42L)
Answer: G
parsing:Comparisons of the same type, such as Integer and Int,long, are automatically removed when compared with long = =, and are compared between different types, and if one is a non-wrapper class, the box is automatically removed. If both parties are wrapper classes, they will not be disassembled and cannot be compared, and the compilation will error, so ABC is wrong. DEF calls the Equals method, because this method first compares types, and I, D, l are different types, so return false. Option G, which is automatically boxed, boxing 42L into a Long type, so when the Equals method is called, the type is the same and the value is the same, so it returns true.
Automatic unboxing of Java wrapper classes