About Question com.enthuware.ets.scjp.v6.2.55 :
Posted: Mon Apr 09, 2018 5:20 am
Regarding option 6
mystifies me somewhat.
I know it actually does work, but the literal 9 is an int literal. So, why doesn't it box to an Integer which would be unassignable to a Short variable?
In the case of primitive assignments such as
again 9 is an int literal, but I can make sense of the statement by imagining that the compiler inserts an implicit cast
Is the best way to think of it, that in this situation also, the compiler inserts a cast to short which is then boxed?
[I manually created the subject as clicking on Discuss in the viewer brings up the wrong page.]
I understand the given reason why it won't compile, but the statementShort k = 9; Integer i = 9; System.out.println(k == i);
Code: Select all
Short k =9;
I know it actually does work, but the literal 9 is an int literal. So, why doesn't it box to an Integer which would be unassignable to a Short variable?
In the case of primitive assignments such as
Code: Select all
byte b = 9;
Code: Select all
byte b = (byte)9;
Code: Select all
Short k = (short)9;