Skip to content

Rewrote named arguments tour #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tutorials/tour/_posts/2017-02-13-named-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
layout: tutorial
title: Named Arguments

disqus: true

tutorial: scala-tour
categories: tour
num: 34
previous-page: default-parameter-values
prerequisite-knowledge: function-syntax
---

When calling methods, you can label the arguments with their parameter names like so:

```tut
def printName(first: String, last: String): Unit = {
println(first + " " + last)
}

printName("John", "Smith") // Prints "John Smith"
printName(first = "John", last = "Smith") // Prints "John Smith"
printName(last = "Smith", first = "John") // Prints "John Smith"
```
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.

```
def printName(first: String, last: String): Unit = {
println(first + " " + last)
}

printName(last = "Smith", "john") // Does not compile
```

Note that named arguments do not work with calls to Java methods.
41 changes: 0 additions & 41 deletions tutorials/tour/_posts/2017-02-13-named-parameters.md

This file was deleted.