Skip to content

Commit f60110f

Browse files
authored
Merge pull request #1211 from realwunan/named-arguments
Simplify Chinese translation of Scala tour: named-arguments.md
2 parents cafaecd + cdd5dbc commit f60110f

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)