diff --git a/_zh-cn/overviews/scala3-book/taste-collections.md b/_zh-cn/overviews/scala3-book/taste-collections.md index afff4ece2e..966872f1a3 100644 --- a/_zh-cn/overviews/scala3-book/taste-collections.md +++ b/_zh-cn/overviews/scala3-book/taste-collections.md @@ -1,5 +1,5 @@ --- -title: Collections +title: 集合 type: section description: This page provides a high-level overview of the main features of the Scala 3 programming language. language: zh-cn diff --git a/_zh-cn/overviews/scala3-book/taste-contextual-abstractions.md b/_zh-cn/overviews/scala3-book/taste-contextual-abstractions.md index 8c92b8e653..cfa5db2f45 100644 --- a/_zh-cn/overviews/scala3-book/taste-contextual-abstractions.md +++ b/_zh-cn/overviews/scala3-book/taste-contextual-abstractions.md @@ -1,5 +1,5 @@ --- -title: Contextual Abstractions +title: 上下文抽象 type: section description: This section provides an introduction to Contextual Abstractions in Scala 3. language: zh-cn diff --git a/_zh-cn/overviews/scala3-book/taste-functions.md b/_zh-cn/overviews/scala3-book/taste-functions.md index ca6725f77d..71cea44649 100644 --- a/_zh-cn/overviews/scala3-book/taste-functions.md +++ b/_zh-cn/overviews/scala3-book/taste-functions.md @@ -1,5 +1,5 @@ --- -title: First-Class Functions +title: 头等函数 type: section description: This page provides an introduction to functions in Scala 3. language: zh-cn diff --git a/_zh-cn/overviews/scala3-book/taste-methods.md b/_zh-cn/overviews/scala3-book/taste-methods.md index 25b6017ba6..521c093a8e 100644 --- a/_zh-cn/overviews/scala3-book/taste-methods.md +++ b/_zh-cn/overviews/scala3-book/taste-methods.md @@ -1,5 +1,5 @@ --- -title: Methods +title: 方法 type: section description: This section provides an introduction to defining and using methods in Scala 3. language: zh-cn diff --git a/_zh-cn/overviews/scala3-book/taste-summary.md b/_zh-cn/overviews/scala3-book/taste-summary.md index 14c44c9bde..1fee593727 100644 --- a/_zh-cn/overviews/scala3-book/taste-summary.md +++ b/_zh-cn/overviews/scala3-book/taste-summary.md @@ -1,5 +1,5 @@ --- -title: Summary +title: 总结 type: section description: This page provides a summary of the previous 'Taste of Scala' sections. language: zh-cn @@ -26,7 +26,7 @@ permalink: "/zh-cn/scala3/book/:title.html" - 如何将对象用于多种目的 - [上下文抽象][contextual]的介绍 -我们还提到,如果您更喜欢使用基于浏览器的游乐场环境而不是 Scala REPL,您还可以使用[Scastie.scala-lang.org](https://scastie.scala-lang.org/?target=dotty) 或 [ScalaFiddle.io](https://scalafiddle.io)。 +我们还提到,如果您更喜欢使用基于浏览器的游乐场环境而不是 Scala REPL,您还可以使用[Scastie](https://scastie.scala-lang.org)。 Scala还有更多功能在这次旋风之旅中没有涵盖。 有关更多详细信息,请参阅本书的其余部分和[参考文档][reference]。 diff --git a/_zh-cn/overviews/scala3-book/taste-toplevel-definitions.md b/_zh-cn/overviews/scala3-book/taste-toplevel-definitions.md index 11b577896f..7deb81d9de 100644 --- a/_zh-cn/overviews/scala3-book/taste-toplevel-definitions.md +++ b/_zh-cn/overviews/scala3-book/taste-toplevel-definitions.md @@ -1,5 +1,5 @@ --- -title: Toplevel Definitions +title: 顶层定义 type: section description: This page provides an introduction to top-level definitions in Scala 3 language: zh-cn @@ -17,6 +17,9 @@ permalink: "/zh-cn/scala3/book/:title.html" 在 Scala 3 中,各种定义都可以在源代码文件的 “顶层” 编写。 例如,您可以创建一个名为 _MyCoolApp.scala_ 的文件,并将以下内容放入其中: +{% tabs toplevel_1 %} +{% tab 'Scala 3 only' for=toplevel_1 %} + ```scala import scala.collection.mutable.ArrayBuffer @@ -43,6 +46,9 @@ type Money = BigDecimal println("show me the code".capitalizeAllWords) ``` +{% endtab %} +{% endtabs %} + 如代码中展示的,无需将这些定义放在 `package`, `class` 或其他构造中。 ## 替换包对象 @@ -50,6 +56,9 @@ type Money = BigDecimal 如果你熟悉Scala 2,这种方法可以取代 _包对象_。 但是,虽然更易于使用,但它们的工作方式类似:当您将定义放在名为 _foo_ 的包中时,您可以在 _foo_ 包内的所有其他包内访问该定义,例如在此示例中的 _foo.bar_ 包中: +{% tabs toplevel_2 %} +{% tab 'Scala 3 only' for=toplevel_2 %} + ```scala package foo { def double(i: Int) = i * 2 @@ -63,6 +72,9 @@ package foo { } ``` +{% endtab %} +{% endtabs %} + 本示例中使用大括号来强调包嵌套。 这种方法的好处是,您可以将定义放在名为 _com.acme.myapp_ 的包下,然后可以在 _com.acme.myapp.model_、_com.acme.myapp.controller_ 等中引用这些定义。