The next seemingly trivial problem shocked the core of my understanding of how primitives work in Java.
I came across a term according to which a variable of a type of a smaller range is allowed to hold a literal value of a type of a wider range if this value falls into this smaller size, range. As I know, Java admits that only among bytes, char, short and int. "implicit narrowing"
For example, a CAN byte variable accepts int if this value is small enough to match a range of byte types.
byte b1 = 3;
byte b2 = 350;
So this works great:
byte k = 3;
But I do not know why the line below does not work !!
Byte k = new Byte(3);
If I do not change the latter to , I get this error compilation : Byte k = new Byte((byte)3)
error: no suitable constructor found for Byte(int)
Byte k = new Byte(3);
^
constructor Byte.Byte(byte) is not applicable
(actual argument int cannot be converted to byte by method invocation conversion)
error message, , , :
"... actual argument int cannot be converted to
byte by method invocation conversion"
:
?! , int literal int literal , ?
, , int. . , , , !