Scala literal identifiers

Super short one today.

But I think it is necessary to know in case you encounter it in the wild

So yes, super short today like I said.

It is possible in Scala to have weird value name that can be sentences. Or pretty much anything for that matter. You can even try to create a value named\nand it works.

The syntax is straightforward, just have to start and end the name of the identifier by`backquote.

It also works for field names in acase classfor instance.

One use case where I have this used pretty often is withgiter8. This is a system to create project template. You can learn more ontheir GitHub. In those template, user can enter any input they want so i can be useful to keep the user input inside the`so the rest of the template do not break.

Another use case is to be able to use reserved keyword, for instance if you would like to name your valuetypethat wouldn't work, but you can name it`type`.

Reveal more information and clues
Load Exercise