BAE
BAE

Reputation: 8936

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

Upvotes: 4

Views: 274

Answers (1)

Yuval Itzchakov
Yuval Itzchakov

Reputation: 149538

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.

Upvotes: 6

Related Questions