我在 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/