简体   繁体   中英

what does the quote mean in the scala import

I read one import statement in scala program:

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

what does

``

mean? Thanks

The backticks are a special form of defining an identifier. This is stated in the Scala specification, 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.

This is used when you need to use reserved keywords as identifiers. In this case, object is a reserved keyword for creating singleton types in 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
_    :    =    =>    <-    <:    <%     >:    #    @

Because object is specified in the reserved keywords, we use the backticks to get around that and allow the compiler to give it the right meaning for the import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM