Wrf to Example4, chapter 6, its bit confusing to understand type conversions .. 1)how can we compare a Integer object with Long object resulted in line no.6 2)On line no 8, why do we need to convert to short, in place of that can we use �Short�. 3)On line 11, how does comparison happens? Specially its comparison of 2 different wrappers.
2) is-a relationship always rely on polymorphism? Can anyone pls explain this statement
3) What does exactly happen when a code between try and finally (there isn�t any catch block) throws an Exception?
In x.equals(L343), the primitive long (L343) is boxed to a Long wrapper for comparison. However, if you check the API for Integer's equals method, you will see that the argument must be an Integer in order for the method to return true. So this returns false, even though the boxed values are the same.
In Short s1 = (short)((new Short((short)343))/(new Short((short)49))), the primitive shorts ((short)343 and (short)49) are first used to create new Short instances. But then these are unboxed and widened to type int for the arithmetic operation of division, which results in an int. That int is then cast back to type short to be assigned to a variable of type Short.
In s1 < new Integer(7 + 1), the Short (s1) and the new Integer are both unboxed for the numeric comparison. (Additionally, the unboxed short is widened to type int.)
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org