You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -24,10 +27,31 @@ printName("John", "Smith") // Prints "John Smith"
24
27
printName(first ="John", last ="Smith") // Prints "John Smith"
25
28
printName(last ="Smith", first ="John") // Prints "John Smith"
26
29
```
30
+
{% endtab %}
31
+
32
+
{% tab 'Scala 3' for=named-arguments-when-good %}
33
+
```scala mdoc
34
+
defprintName(first: String, last: String):Unit=
35
+
println(first +""+ last)
36
+
37
+
printName("John", "Smith") // Prints "John Smith"
38
+
printName(first ="John", last ="Smith") // Prints "John Smith"
39
+
printName(last ="Smith", first ="John") // Prints "John Smith"
40
+
```
41
+
{% endtab %}
42
+
43
+
{% endtabs %}
44
+
27
45
Notice how the order of named arguments can be rearranged. However, if some arguments are named and others are not, the unnamed arguments must come first and in the order of their parameters in the method signature.
28
46
47
+
{% tabs scala-2-and-3-demo %}
48
+
49
+
{% tab 'Scala 2 and 3' for=named-arguments-when-error %}
29
50
```scala mdoc:fail
30
51
printName(last ="Smith", "john") // error: positional after named argument
31
52
```
53
+
{% endtab %}
54
+
55
+
{% endtabs %}
32
56
33
57
Named arguments work with calls to Java methods, but only if the Java library in question was compiled with `-parameters`.
0 commit comments