Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Java will always try to use the most specific applicable version of a method that's available (see <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.5" rel="noreferrer">JLS §15.12.2</a>).</p> <p><code>Object</code>, <code>char[]</code> and <code>Integer</code> can all take <code>null</code> as a valid value. Therefore all 3 version are applicable, so Java will have to find the most specific one.</p> <p>Since <code>Object</code> is the super-type of <code>char[]</code>, the array version is more specific than the <code>Object</code>-version. So if only those two methods exist, the <code>char[]</code> version will be chosen.</p> <p>When both the <code>char[]</code> and <code>Integer</code> versions are available, then <strong>both</strong> of them are more specific than <code>Object</code> but none is more specific than the other, so Java can't decide which one to call. In this case you'll have to explicitly mention which one you want to call by casting the argument to the appropriate type.</p> <p>Note that in practice this problem occurs far more seldom than one might think. The reason for this is that it only happens when you're explicitly calling a method with <code>null</code> or with a variable of a rather un-specific type (such as <code>Object</code>).</p> <p>On the contrary, the following invocation would be perfectly unambiguous:</p> <pre><code>char[] x = null; doSomething(x); </code></pre> <p>Although you're still passing the value <code>null</code>, Java knows exactly which method to call, since it will take the type of the variable into account.</p>
 

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