官术网_书友最值得收藏!

Symbol literals

A symbol has a name, and it can be defined as a single quote (') followed by alphanumeric identifier:

scala> val aSymbol = 'givenName
aSymbol: Symbol = 'givenName

scala> aSymbol.name
res10: String = givenName

We don't use symbols a lot in normal Scala programs. If we try to dig down deeper into symbols in Scala, we get to know that everything that we define in Scala and give a name to is a symbol. We can check the absolute type for a symbol:

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> typeOf[Symbol]
res12:reflect.runtime.universe.Type= scala.reflect.runtime.universe.Symbol

So this Symbol is from Scala's reflection package. We're not going to dig any deeper. If you're curious though, I would recommend going through the Scala documentation at http://docs.scala-lang.org/overviews/reflection/symbols-trees-types.html.

So that's all about Symbol literals.

主站蜘蛛池模板: 保靖县| 岳西县| 临夏县| 鄂托克旗| 兴海县| 土默特右旗| 铜鼓县| 绥芬河市| 杭锦旗| 五家渠市| 朝阳市| 资兴市| 永川市| 华阴市| 阿鲁科尔沁旗| 乳山市| 栾城县| 中牟县| 莱阳市| 南靖县| 自贡市| 大理市| 宁安市| 高雄市| 泸溪县| 宜川县| 镇江市| 内江市| 井陉县| 奉化市| 四川省| 凉山| 凤台县| 武陟县| 交口县| 克东县| 莒南县| 昆山市| 会宁县| 太谷县| 扎兰屯市|