Skip to content

Commit 66f52fe

Browse files
committed
Rewrote named arguments tour
1 parent d546dd2 commit 66f52fe

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

Diff for: tutorials/tour/_posts/2017-02-13-named-arguments.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
layout: tutorial
3+
title: Named Arguments
4+
5+
disqus: true
6+
7+
tutorial: scala-tour
8+
categories: tour
9+
num: 34
10+
previous-page: default-parameter-values
11+
prerequisite-knowledge: function-syntax
12+
---
13+
14+
When calling methods, you can label the arguments with their parameter names like so:
15+
16+
```tut
17+
def printName(first: String, last: String): Unit = {
18+
println(first + " " + last)
19+
}
20+
21+
printName("John", "Smith") // Prints "John Smith"
22+
printName(first = "John", last = "Smith") // Prints "John Smith"
23+
printName(last = "Smith", first = "John") // Prints "John Smith"
24+
```
25+
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.
26+
27+
```
28+
def printName(first: String, last: String): Unit = {
29+
println(first + " " + last)
30+
}
31+
32+
printName(last = "Smith", "john") // Does not compile
33+
```
34+
35+
Note that named arguments do not work with calls to Java methods.

Diff for: tutorials/tour/_posts/2017-02-13-named-parameters.md

-41
This file was deleted.

0 commit comments

Comments
 (0)