coder25 coder25 - 1 year ago 90
Scala Question

Symbols to represent a string scala

I went through the answer on Purpose of Scala's Symbol?

I want to create a Symbol but it has space in it.

Ex:

val s = "Hello World"
val syb = 'Hello World


syb
gives compile time error. Is it possible to create a Symbol with spaces?

Answer Source

It is possible to create a Symbol with spaces with the Symbol.apply method:

scala> val syb = Symbol("Hello World")
syb: Symbol = 'Hello World
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download