mishrajicoder
New Member
- Joined
- Oct 17, 2022
- Messages
- 6
- Thread Author
-
- #1
I was reading Programming in Scala 2nd Edition when I came across this:
So, because yield is a reserved term in Scala, if I use yield with backticks,
Would disregard the Scala yield and allow me to use the yield function of the Java Thread class instead?
Thank you!
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."The notion is that you may insert any string that the runtime accepts as an identifier between backticks."
So, because yield is a reserved term in Scala, if I use yield with backticks,
Code:
Thread.`yield`()
Thank you!
Solution
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 Link Removed might be helpful.
AlishS
New Member
- Joined
- Oct 27, 2022
- Messages
- 9
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 Link Removed might be helpful.