Method signature matching can get a bit confusing. Primitive widening
comes first, and then classes including boxing, which can be widened
to Object. Looking for a varargs match comes last.
So the first call is widened to Object and finds a match there, before it
gets to vararg, where it would also match. The second call is a direct
hit. In the third call, the int widens all the way to double, but finds no
match. It is then boxed - again no match. Finally Integer is widened
and hits on Object. I hope this helps.
mohitkumar gupta wrote:why will there be a direct hit in case of second call ?
I cannot understand your question properly, but the second call is not that hard to understand. You called sifter with an B and there was a sifter method taking B as parameter so it got called. The B... version of sifter didn't get called because it was not a better match...
In the first case for shifter(aa) line 17 is not possible coz b is a sub class of a so it is widened to object and line 18 is executed
2nd case for shifter(ba) simply line 17 is called
3rd case for shifter(7), 7 is autoboxed to Integer and then widened to Object so line 18 is executed.
Always remember "Only consider the var-arg parameter methods when no Non-var-arg methods are possible"
I hope you understand it clearly.. any more queries???