I just found some scala code which has a strange class name:
class `This is a cool class` {}
and method name:
def `cool method` = {}
We can use a sentence for a class or method name!
It’s very cool and useful for unit-testing:
class UserTest {
def `user can be saved to db` {
// testing
}
}
But why we can do this? How to understand it?
This feature exists for the sake of interoperability. If Scala has a reserved word (
with, for example), then you can still refer to code from other languages which use it as a method or variable or whatever, by using backticks.Since there was no reason to forbid nearly arbitrary strings, you can use nearly arbitrary strings.