Is it possible to write a val
or a def
that starts with a number? I know scala val
s and def
s 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.
Is it possible to write a val
or a def
that starts with a number? I know scala val
s and def
s 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.
You can use just about anything in a value name if you use backticks:
val `512MB` = 536870912
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.