Skip to content

Simplify Chinese translation of Scala tour: named-arguments.md #1211

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 2 commits into from
Nov 30, 2018
Merged
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion _zh-cn/tour/named-arguments.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: tour
title: Named Arguments
title: 命名参数

discourse: false

Expand All @@ -13,3 +13,22 @@ language: zh-cn
next-page: packages-and-imports
previous-page: default-parameter-values
---

当调用方法时,你可以像下面这样使用参数名称来标记参数:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实际参数可以通过其对应的形式参数的名称来标记

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot.


```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"
```
注意使用命名参数时,顺序是可以重新排列的。 但是,如果某些参数被命名了,而其他参数没有,则未命名的参数要按照其方法签名中的参数顺序放在前面。

```tut:fail
printName(last = "Smith", "john") // error: positional after named argument
```

注意调用 Java 方法时不能使用命名参数。