Skip to content

Commit 6bd83a4

Browse files
committed
Simplify Chinese translation of Scala tour: named-arguments.md
1 parent d9293e6 commit 6bd83a4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

_zh-cn/tour/named-arguments.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: tour
3-
title: Named Arguments
3+
title: 命名参数
44

55
discourse: false
66

@@ -13,3 +13,22 @@ language: zh-cn
1313
next-page: packages-and-imports
1414
previous-page: default-parameter-values
1515
---
16+
17+
当调用方法时,你可以像下面这样使用参数名称来标记参数:
18+
19+
```tut
20+
def printName(first: String, last: String): Unit = {
21+
println(first + " " + last)
22+
}
23+
24+
printName("John", "Smith") // Prints "John Smith"
25+
printName(first = "John", last = "Smith") // Prints "John Smith"
26+
printName(last = "Smith", first = "John") // Prints "John Smith"
27+
```
28+
注意使用命名参数时,顺序是可以重新排列的。 但是,如果某些参数被命名了,而其他参数没有,则未命名的参数要按照其方法签名中的参数顺序放在前面。
29+
30+
```tut:fail
31+
printName(last = "Smith", "john") // error: positional after named argument
32+
```
33+
34+
注意调用 Java 方法时不能使用命名参数。

0 commit comments

Comments
 (0)