Unable to access the current millisecond time in scala using java.lang.System.currentTimeMillis ();

When I use the code below in scala, I get an exception at runtime:

java.lang.NoSuchMethodError: main Exception in thread "main"

object Driver { def main(args:Array[String]) = { java.lang.System.currentTimeMillis(); } } 

But when I delete java.lang.System.currentTimeMillis (); found the main method.

Why is this?

+4
source share
3 answers

This is an equal sign!

This calls Scala to output the return type of main as Long (Scala) / Long (at the JVM level). When you delete it, it appears Unit / void . Similarly, when you delete a call to currentTimeMillis .

+16
source

If you only need time you can use compat.Platform.currentTime

also your object should be

 object Driver { def main(args:Array[String]){ java.lang.System.currentTimeMillis(); } } 
+1
source

def main(args:Array[String]): Unit = { is the exact signature for main() . Removing = also seems to be a solution, but less error prone.

+1
source

All Articles