|
Scala Library
|
|
scala/Application.scala]
trait
Application
extends AnyRef
The Application trait can be used to quickly turn objects
into executable programs, but is not recommended. Here is an example:
object Main extends Application {
Console.println("Hello World!")
}
Here, object Main inherits the main method
of Application. The body of the Main object
defines the main program. This technique does not work if the main
program depends on command-line arguments (which are not accessible
with the technique presented here).
It is possible to time the execution of objects that inherit from class
Application by setting the global scala.time
property. Here is an example for benchmarking object Main:
java -Dscala.time Main
In practice the Application trait has a number of serious
pitfalls:
object
extending Application is run as part of the static initialization
which occurs before Application's main method
even begins execution.object extending Application takes place during
static initialization, concurrent code will always deadlock if
it must synchronize with the enclosing object.object extending
Application. This can lead to a significant
performance degradation.| Value Summary | |
val
|
executionStart
: Long
The time when execution of this program started.
|
| Method Summary | |
def
|
main
(args : Array[java.lang.String]) : Unit
The default main method.
|
| Methods inherited from AnyRef | |
| getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
| Methods inherited from Any | |
| ==, !=, isInstanceOf, asInstanceOf |
| Value Details |
| Method Details |
def
main(args : Array[java.lang.String]) : Unit
args - the arguments passed to the main method|
Scala Library
|
|