Most specific method with matches of both fixed/variable arity (varargs)

◇◆丶佛笑我妖孽 提交于 2019-11-28 12:41:09

The first method resolution phase considers only fixed arity methods and the process is terminated if a match is found, before any varargs methods are considered.

From http://docs.oracle.com/javase/specs/jls/se6/html/expressions.html#15.12.2.2

15.12.2.2 Phase 1: Identify Matching Arity Methods Applicable by Subtyping

If no method applicable by subtyping is found, the search for applicable methods continues with phase 2 (§15.12.2.3). Otherwise, the most specific method (§15.12.2.5) is chosen among the methods that are applicable by subtyping.

(My emphasis.)

Yoni Roit

I can't point you to the spec, but logically,

getSomething(String...args) 

translates to

getSomething(String[] args)

with no ambiguity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!