The code:
int i = 1;
byte b = i;
will not compile. Explicit cast needed. Just to add something more, the following code compiles fine because the compiler has a way to know that i has the value 1 at compile-time:
final int i = 1;
byte b = i;
Remember that a compiler does not intrepret the
Java code it parses, and thus, has no way to know the value of a variable during the parsing process. It can only know the value of constants (final fields) since they are definitely fixed at compile time.