Var-arg of object arrays vs. object array — trying to understand a SCJP self test question

前端 未结 2 882
面向向阳花
面向向阳花 2021-01-05 23:45

I\'m having trouble understanding this question, and the explanation of the answer for an SCJP 1.6 self test question. Here is the problem:

class A { }
class         


        
2条回答
  •  花落未央
    2021-01-06 00:07

    The book is trying to explain why the first two overloads are never selected: because the var-args marker ... makes them be used only if every other possible overload fails. In this case, this doesn't happen -- the two sentences starting with "Remember" is explaining WHY it doesn't happen, why other possible overloads exists in the first and last case (the second case and its match with the 3rd overload of sifter is obvious): an array is an object, and an int can be boxened then widened to an Object, so the 4th overload matches the first and last ones of the calls to sifter.

提交回复
热议问题