Default arguments in Scala 3

My recollection is that in Scala 2, default arguments (in a constructor, method, or function) had to be at the end of the argument list, preceded by all arguments without a default value. That is apparently not true in Scala 3. Is that a change, or am I missing something? Where can I find an explanation of the rules for Scala 3? Thanks.

Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.2).
Type in expressions for evaluation. Or try :help.

scala> def f(i: Int = 42, j: String) = j*i
def f(i: Int, j: String): String

scala> f(j=".")
val res0: String = ..........................................

Spec is at this link.

Maybe you were remembering something about implicit parameter lists.

Sorry, I must have been thinking of C++ or Python (neither of which I have used for many years, so I could be wrong about them too).

What you are thinking has long been true for C++. Without named parameters, it is required.

1 Like