scala - 引用在 scala 导入中是什么意思

标签 scala

我在 Scala 程序中阅读了一个导入语句:

import org.javaswift.joss.command.impl.`object`._

做什么

``



意思?谢谢

最佳答案

反引号是定义标识符的一种特殊形式。这在 Scala 规范中说明,Section § 1.1 (Identifiers) :

Finally, an identifier may also be formed by an arbitrary string between back-quotes (host systems may impose some restrictions on which strings are legal for identifiers). The identifier then is composed of all characters excluding the backquotes themselves.



当您需要使用保留关键字作为标识符时使用。在这种情况下,object是在 Scala 中创建单例类型的保留关键字:

The following names are reserved words instead of being members of the syntactic class id of lexical identifiers:


abstract    case        catch       class       def
do          else        extends     false       final
finally     for         forSome     if          implicit
import      lazy        macro       match       new
null        object      override    package     private
protected   return      sealed      super       this
throw       trait       try         true        type
val         var         while       with        yield
_    :    =    =>    <-    <:    <%     >:    #    @

因为 object在保留关键字中指定,我们使用反引号来解决这个问题,并允许编译器为导入赋予正确的含义。

关于scala - 引用在 scala 导入中是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50491315/

相关文章:

scala - Spark Dataset select with typedcolumn

scala - => 和 () => 在 Scala 中意味着什么

scala:并行集合不起作用?

scala - Spark的MLlib库中预定义的Streaming k-means聚类是有监督的还是无监督的?

java - 使用 eclipse 重写 Scala 中的 Java 方法

scala - 如何使用 Play Framework (scala)在HTML中打印@符号

scala - 类型参数子句中的广义约束?

scala - 给定序列中的一个元素,如何获取前一个元素?

java - 如何在Jupyter notebook中显示spark进度条(使用pyspark)

scala - Play Framework 中的对列表