Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The rules of method resolution in Java require that a match be attempted <em>without</em> auto-(un)boxing and variable arity <em>before</em> attempting a match <em>with</em> those features. This ensures source compatibility with language versions that predate those features.</p> <p>The rules for overload resolution are described in the JLS (§15.12.2):</p> <blockquote> <p>The process of determining applicability begins by determining the potentially applicable methods (§15.12.2.1).</p> <p>The remainder of the process is split into three phases, to ensure compatibility with versions of the Java programming language prior to Java SE 5.0. The phases are:</p> <ol> <li><p>The first phase (§15.12.2.2) performs overload resolution without permitting boxing or unboxing conversion, or the use of variable arity method invocation. If no applicable method is found during this phase then processing continues to the second phase. This guarantees that any calls that were valid in the Java programming language before Java SE 5.0 are not considered ambiguous as the result of the introduction of variable arity methods, implicit boxing and/or unboxing. However, the declaration of a variable arity method (§8.4.1) can change the method chosen for a given method method invocation expression, because a variable arity method is treated as a fixed arity method in the first phase. For example, declaring m(Object...) in a class which already declares m(Object) causes m(Object) to no longer be chosen for some invocation expressions (such as m(null)), as m(Object[]) is more specific.</p></li> <li><p>The second phase (§15.12.2.3) performs overload resolution while allowing boxing and unboxing, but still precludes the use of variable arity method invocation. If no applicable method is found during this phase then processing continues to the third phase. This ensures that a method is never chosen through variable arity method invocation if it is applicable through fixed arity method invocation.</p></li> <li><p>The third phase (§15.12.2.4) allows overloading to be combined with variable arity methods, boxing, and unboxing.</p></li> </ol> <p>Deciding whether a method is applicable will, in the case of generic methods (§8.4.4), require that type arguments be determined. Type arguments may be passed explicitly or implicitly. If they are passed implicitly, they must be inferred (§15.12.2.7) from the types of the argument expressions.</p> <p>If several applicable methods have been identified during one of the three phases of applicability testing, then the most specific one is chosen, as specified in section §15.12.2.5.</p> </blockquote> <p>In your example, there are two candidates during Step 1: the method with an <code>Object[]</code> parameter, and the method with an <code>Integer[][]</code> parameter. The argument type at your call site is <code>Integer[]</code>. Since <code>Object[]</code> is assignable from <code>Integer[]</code>, but <code>Integer[][]</code> is not, a single applicable method has been found, and overload resolution halts there. Steps 2 and 3 are never reached in this case.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload