Java: overloaded method resolution and varargs — confusing example

前端 未结 2 860
后悔当初
后悔当初 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 09:07

    Vararg methods can be called with multiple parameters (a, b, c) or as an array ({a, b, c}). Because you are passing an array that matches the type of the varargs it takes precedence.

    Reference: http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.4.1

提交回复
热议问题