When I use below code in scala I get a runtime exception :
java.lang.NoSuchMethodError: main Exception in thread "main"
object Driver {
def main(args:Array[String]) = {
java.lang.System.currentTimeMillis();
}
}
But when I remove java.lang.System.currentTimeMillis(); the main method is found.
Why is this ?
It's the equal sign!
That's causing Scala to infer the return type of main
to be Long
(Scala) / long
(at the JVM level). When you remove it, it infers Unit
/ void
. Likewise when you remove the call to currentTimeMillis
.
def main(args:Array[String]): Unit = {
is the exact signature for main()
. Removing =
seems also a solution, but less error-prone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With