Just wondered why is it possible to pass Integer as argument where method parameter is of int type and vice versa?
public class Salmon {
public static Integer foo(Integer a, int b){
return a - b;
}
public static void main(String[] args) {
Integer a = 10;
int b = 1;
foo(b, a);
}
}
This is auto-boxing and auto-unboxing. Basically the compiler puts in calls to
Integer.valueOf()orx.intValue()appropriately.The exact mechanism isn’t actually specified, but the relevant sections of the spec are 5.1.7 and 5.1.8.