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

前端 未结 2 1779
一生所求
一生所求 2020-12-11 08:17

In section 15.12.2.5 of the Java Language Specification, it talks about how to choose the most specific method in both cases of methods with fixed arity and methods of varia

相关标签:
2条回答
  • 2020-12-11 08:43

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

    getSomething(String...args) 
    

    translates to

    getSomething(String[] args)
    

    with no ambiguity

    0 讨论(0)
  • 2020-12-11 08:46

    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.)

    0 讨论(0)
提交回复
热议问题