Java: overloaded method resolution and varargs — confusing example

前端 未结 2 858
后悔当初
后悔当初 2020-12-31 08:31

Just when I thought I understood JLS15.12 as it applied to varargs, here\'s this example:

package com.example.test.reflect;

public class MethodResolutionTes         


        
2条回答
  •  天涯浪人
    2020-12-31 08:57

    In section 8.4.1:

    If the last formal parameter is a variable arity parameter of type T, it is considered to define a formal parameter of type T[].

    Since you're explicitly providing an array, this allows the second two calls to match the variable arity method in the first phase, without consideration of variable arity.

提交回复
热议问题