Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
SCJP 1.4(Cleared)<br />SCWCD X.XX Aspirant
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Martin Simons:
I don't think it has anything at all to do with varargs. I think it has to do with autoboxing which makes Integer and int essentially the same thing, which makes those two methods indistinguishable.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Neelesh Bodas:
According to Choosing the most specific method rule, when more than one overloaded methods are applicable, the compiler will choose the most specific method. In the current case, neither of the two methods is "more specifc" than other. Hence the compiler will throw an ambiguity error.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Barry Gaunt:
Why, then, does the compiler, when given an argument of 1, have no problem choosing between int[] and Integer... ? It chooses the method with the var-args - Integer...
Let m be a name and suppose that there are two declarations of methods named m, each having n parameters. Suppose that one declaration appears within a class or interface T and that the types of the parameters are T1, . . . , Tn; suppose moreover that the other declaration appears within a class or interface U and that the types of the parameters are U1, . . . , Un. Then the method m declared in T is more specific than the method m declared in U if and only if both of the following are true:
T can be converted to U by method invocation conversion.
Tj can be converted to Uj by method invocation conversion, for all j from 1 to n.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |