Does Scala have any syntactic sugar to replace the following code:
val thread = new Thread(new Runnable {
def run() {
println(\"hello world\")
}
SAM types are supported using invokeDynamic since scala-2.12 similar to JDK-8, Below was tested on 2.12.3 - Release notes about SAM can be found here - http://www.scala-lang.org/news/2.12.0/
object ThreadApp extends App {
println("Main thread - begins")
val runnable: Runnable = () => println("hello world - from first thread")
val thread = new Thread(runnable)
println("Main thread - spins first thread")
thread.start()
val thread2 = new Thread(() => println("hello world - from second thread"))
println("Main thread - spins second thread")
thread2.start
thread.join()
thread2.join()
println("Main thread - end")
}