That's a special case. From the
JLS section on assignment conversion:
<blockquote>
In addition, a narrowing primitive conversion may be used if all of the following conditions are satisfied:
- The expression is a constant expression of type int.
- The type of the variable is byte, short, or char.
- The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable.
</blockquote>
That's the case here, so the compiler performs a narrowing conversion without a cast.
To see that the default is int, try this:
<code><pre>public class
Test {
static void method(byte b) {
System.out.println(b + " is a byte!");
}
static void method(short s) {
System.out.println(s + " is a short!");
}
static void method(int i) {
System.out.println(i + " is an int!");
}
static void method(long l) {
System.out.println(l + " is a long!");
}
public static void main(
String[] args) {
method(1);
}
}</pre></code>