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

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.

主站蜘蛛池模板: 伊春市| 洛南县| 墨竹工卡县| 乌审旗| 河津市| 军事| 县级市| 兴城市| 福贡县| 政和县| 龙山县| 榆林市| 台州市| 铜川市| 玉田县| 丰镇市| 德化县| 大新县| 阿巴嘎旗| 揭西县| 神农架林区| 仲巴县| 南投县| 呼伦贝尔市| 南陵县| 南陵县| 六安市| 扎鲁特旗| 固阳县| 略阳县| 宜良县| 池州市| 灯塔市| 镇雄县| 九龙坡区| 唐河县| 南溪县| 永州市| 包头市| 玛曲县| 长汀县|