-1

Is it possible to write a val or a def that starts with a number? I know scala vals and defs can have pretty crazy characters in them. I'd like to make some constants like:

val 512MB = 536870912

But not sure if this is possible.

user3685285
  • 6,066
  • 13
  • 54
  • 95

2 Answers2

4

You can use just about anything in a value name if you use backticks:

val `512MB` = 536870912
Jack Leow
  • 21,945
  • 4
  • 50
  • 55
1

As @Jack Leow mentioned, you can use any name with the backticks, but you'll have to use them all the time. Did you consider to use DSL in-place where you need these consts? In this case you can write something like this in your code:

val mySize = 512 MB

Please check this thread for more details how you can achieve that.

fenixil
  • 2,106
  • 7
  • 13