public class TestWrapper1{
public static void main(
String[] args) throws Exception {
short s1 = 400; // line 1
shortParam(s1);
shortParam(300); // line 2
}
static void shortParam(short s) // line 3{System.out.println(s);
}
}
I think this is the answer I Am not sure
1)At line 1 400(int literal) is assigned to short.Compiler can verify range at the compile time so no problem.
2)At line 2 300(int literal once again) is passed as argument to the function.When function is called in line 2, assignment happens at runtime.
So I think compiler will not be able to determine range.So cast is always necessary during method call..