There is no error during auto-boxing of constants with int and short types to Byte, but constant with long type do has error. Why?
final int i = 3;
Byte b = i; // no error
final short s = 3;
Byte b = s; // no error
final long l = 3;
Byte b = l; // error
From JLS Sec 5.2, "Assignment contexts" (emphasis mine):
It's simply not allowed for
longs by the spec.Note that the second bullet point here says that this happens irrespective of the boxing: assigning a constant
longexpression to abytevariable would similarly fail: