Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is that when you use default arguments, its name and the method name is used to generate a static attribute, this way: <code>[methodName]$default$[argumentPosition]</code>, in your case it will be <code>variance$default$2</code>, so if both have default arguments, the compiler will try to generate 2 static attributes with the same name.</p> <p>if the type of the other arguments in the method were used, this could be avoided. You may <a href="http://docs.scala-lang.org/sips/sip-submission.html">submit a SIP</a> Proposal to change this behaviour in the compiler.</p> <p>You can read more about this on this <a href="https://groups.google.com/forum/#!msg/scala-user/FyQK3-cqfaY/fXLHr8QsW_0J">post</a></p> <p>If you want to check by yourself, try compiling your object with each method and inspect the class using <code>javap [XXX]</code>, where is the name of the object or class, in your case <code>javap Stats2</code>.<br> Your first method will give: </p> <pre><code>public final class Stats2 extends java.lang.Object{ public static final int variance$default$2(); public static final double variance(scala.collection.Seq, int); } </code></pre> <p>and your second method will give: </p> <pre><code>public final class Stats2 extends java.lang.Object{ public static final int variance$default$2(); public static final double variance(scala.collection.Seq, int, scala.Function1); } </code></pre> <p>finally, by removing the default value for dof in the second method, we get:</p> <pre><code>public final class Stats2 extends java.lang.Object{ public static final double variance(scala.collection.Seq, int, scala.Function1); } </code></pre> <p>So the <code>static final int variance$default$2()</code> is what is making the compilation to fail, which is generated by the default value.</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