- Learning Scala Programming
- Vikash Sharma
- 130字
- 2021-06-30 19:07:50
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.
推薦閱讀
- VSTO開發(fā)入門教程
- Web Application Development with MEAN
- Python機器學習實戰(zhàn)
- Node.js Design Patterns
- RabbitMQ Cookbook
- Mastering Android Game Development
- Principles of Strategic Data Science
- 遠方:兩位持續(xù)創(chuàng)業(yè)者的點滴思考
- Moodle 3 Administration(Third Edition)
- Learning Bootstrap 4(Second Edition)
- C# 7.1 and .NET Core 2.0:Modern Cross-Platform Development(Third Edition)
- Spark技術(shù)內(nèi)幕:深入解析Spark內(nèi)核架構(gòu)設(shè)計與實現(xiàn)原理
- Learning Ionic(Second Edition)
- 3D Printing Designs:Design an SD Card Holder
- 移動智能系統(tǒng)測試原理與實踐