Kedar Pethe wrote:Chapter 6, Self test Q3.
Correct answers - B,C,D
How come answer is also D option??
I know that two Integer wrapper objects can be compared.
Using simple relational operator,
How can a short object be compared with an Integer object?
How does Java compare the two different wrapper's values??
The answer is .... it depends.
If you are using a "==" or "!=" as the operator, it will do an instance comparison, meaning whether the two instances are the same instance.... and of course, this will fail to compile as Short and Integer are not sub/super classes of each other.
Otherwise, such as what you did in the example, it will do a value comparison, meaning it will unbox both sides first.
Henry