I have the following code:
byte b=10;
System.out.println("Test b:"+b);
This codes is compiled and works without problems. However, I cant understand why. 10 is literal here and it is integer literal (default for integer). So we have here casting as on the left side we have byte and on the right side we have integer. And this is narrowing as byte<integer
. As I understand narrowing must always be explicit casting otherwise the code won't compile. Could anyone explain why this code works?