Which method is called? (Integer… a) vs. (int a, int b)

后端 未结 5 548
无人共我
无人共我 2021-02-05 06:10

I just found out about a very interesting Java trick:

void method1(Integer... a){
}

So you can give this method as many integers as you want.

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 06:49

    varargs has the least priority. If no other matched method found then only it gets called.It is just like the default case of SWITCH case.

提交回复
热议问题