Reputation: 209
Create a Java package named 'val' and put a class in it and try to import it in a Scala program. scalac will fail with the following error message:
[scalac] /tmp/Hello.scala:6: error: identifier expected but 'val' found.
[scalac] import net.slimweb.ann.val.NotEmpty
[scalac] ^
[scalac] one error found
Any ideas?
Upvotes: 2
Views: 369
Reputation: 29113
import net.slimweb.ann.`val`.NotEmpty
Backquotes can be used to escape symbols:
scala> val `val` = 1
val: Int = 1
scala> class `val`
defined class val
Except for using them to define symbols with reserved names, or call legacy java code that has keywords as methods (e.g., a method named with), they can also be used for symbols with spaces in them or otherwise weird characters
Upvotes: 14