Android Scala literal identifiers require explanation (backticks)

mishrajicoder

New Member
I was reading Programming in Scala 2nd Edition when I came across this:
"The notion is that you may insert any string that the runtime accepts as an identifier between backticks."
I'm not sure why I'd want to utilize this. In this article, I've read provided an example of how to access the static yield function in Java's Thread class.
So, because yield is a reserved term in Scala, if I use yield with backticks,
Code:
Thread.`yield`()
Would disregard the Scala yield and allow me to use the yield function of the Java Thread class instead?
Thank you!
 
Yes, that is correct. By putting the word 'yield' in backticks, you are telling the Scala compiler to use the yield function from the Java Thread class instead of the Scala one. This allows you to access features from Java classes that might otherwise be unavailable in Scala due to name collisions. The additional resource might be helpful.
 
Back
Top