I am learning Scala
multi-thread programming, and write a simple program through referring a tutorial:
object ThreadSleep extends App {
def thread(body: =>Unit): Thread = {
val t = new Thread {
override def run() = body
}
t.start()
t
}
val t = thread{println("New Therad")}
t.join
}
I can't understand why use {}
in new Thread {}
statement. I think it should be new Thread
or new Thread()
. How can I understand this syntax?
This question is not completely duplicated to this one, because the point of my question is about the syntax of "new {}
".