In Scala; should I use the App trait?

The problem with the Application trait is actually described in its documentation: (1) Threaded code that references the object will block until static initialization is complete. However, because the entire execution of an object extending Application takes place during static initialization, concurrent code will always deadlock if it must synchronize with the enclosing object. This …

Read more

Where are the the argv strings of the main function’s parameters located?

Here’s what the C standard (n1256) says: 5.1.2.2.1 Program startup… 2 If they are declared, the parameters to the main function shall obey the following constraints: The value of argc shall be nonnegative. argv[argc] shall be a null pointer. If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive …

Read more

Get name of executable jar from within main() method [duplicate]

Here you go: new java.io.File(SomeClassInYourJar.class.getProtectionDomain() .getCodeSource() .getLocation() .getPath()) .getName() Edit: I saw your comment about getSourceCode API. Well, this is probably the best you can do in Java. About getCodeSource() returning null, I think it mainly happens on classes in java.lang.* and other special classes for which the source location is “hidden”. Should work for …

Read more

Main method in Scala

To answer your question, have a look on the following : I made a scala class, compiled and decompiled it, and what I got is interesting. class MyScalaClass{ def main(args: Array[String]): Unit = { println(“Hello from main of class”) } } Compiled from “MyScalaClass.scala” public class MyScalaClass { public void main(java.lang.String[]); public MyScalaClass(); } So …

Read more