Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(Assuming you want the question of how to resolve overloads when you need to pass a null):</p> <p>Just as you would in Java, by ascribing the type corresponding to the overload you wish to invoke (in Java you'd cast, but it amounts to the same thing: an assertion of the static type to assign to the <code>null</code>):</p> <pre><code>scala&gt; object O { def m(i: Int, s: String): String = s * i; def m(i: Int, l: List[String]): String = l.mkString(":") * i } defined module O scala&gt; O.m(23, null) &lt;console&gt;:7: error: ambiguous reference to overloaded definition, both method m in object O of type (i: Int,l: List[String])String and method m in object O of type (i: Int,s: String)String match argument types (Int,Null) O.m(23, null) ^ scala&gt; O.m(23, null: String) res4: String = nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull scala&gt; O.m(23, null: List[String]) java.lang.NullPointerException at O$.m(&lt;console&gt;:5) at .&lt;init&gt;(&lt;console&gt;:7) at .&lt;clinit&gt;(&lt;console&gt;) at RequestResult$.&lt;init&gt;(&lt;console&gt;:9) at RequestResult$.&lt;clinit&gt;(&lt;console&gt;) at RequestResult$scala_repl_result(&lt;console&gt;) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) at scala.tools.nsc.Interpreter$Request$$anonfun$loadAndRun$1$$anonfun$apply$18.apply(Interpreter.scala:981) at scala.util.control.Exception$Catch.apply(Exception.scala:7... scala&gt; </code></pre>
 

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