Saturday, June 03, 2006

Widening Wins Boxing when alone: Causes confusion combined with Var-args

For the following methods:
public void test(long... l)
{
System.out.println("Widen varargs");
}
public void test(Integer... i)
{
System.out.println("Boxed and vararg'ed");
}
invocation of int i =5; test(i) will cause confusion to compiler. However if the methods are changed from varargs to normal parameters(long and Integer), then widening method will win over the Boxing parameter method. So, widening wins boxing when alone. But not when combined with var-args.

No comments: