I studied the most specific method tutorial.I understand that when there are two or more applicable methods are there then the compiler will choose the specific method.That method can be chosen by comparing the applicable method arguments.The method1 arguments that are valid for (i.e they can be assigned to)method2 arguments but not vice versa then method1 is most specific.In the first example i posted method1 arguments(int) can be easily assigned to method arguments(Integer) and method2(Integer) arguments are also easily assigned to method1(int). So compiler cannot determine the specific method.
This is the first example.
class Boxing2
{
public static void main(String args[])
{
dostuff(4);
}
static void dostuff(int... z) //method1
{
System.out.println("int");
}
static void dostuff(Integer... z) //method2
{
System.out.println("Integer");
}
}
I understood this much concept from what i have studied.Is this right?Then i have another doubt regarding the below example?
class Boxing2
{
public static void main(String args[])
{
dostuff(4);
}
static void dostuff(long... z) //method1
{
System.out.println("int");
}
static void dostuff(Integer... z) //method2
{
System.out.println("Integer");
}
}
In this example method1 arguments(long) cannot be assigned to method2 arguments(Integer) but method2 arguments(Integer) can be assigned to method1 arguments(long).So method2 is most specific methos.Why compiler cannot determine this one and showing an error that is same error as in first example?