App
The App
trait can be used to quickly turn objects
into executable programs. Here is an example:
object Main extends App {
Console.println("Hello World: " + (args mkString ", "))
}
No explicit main
method is needed. Instead,
the whole class body becomes the “main method”.
args
returns the current command line arguments as an array.
Caveats
It should be noted that this trait is implemented using the DelayedInit functionality, which means that fields of the object will not have been initialized before the main method has been executed.
Future versions of this trait will no longer extend DelayedInit
.
- Source
- App.scala
Value members
Concrete methods
Deprecated methods
The init hook. This saves all initialization code for execution within main
.
This method is normally never called directly from user code.
Instead it is called as compiler-generated code for those classes and objects
(but not traits) that inherit from the DelayedInit
trait and that do not
themselves define a delayedInit
method.
- Value Params
- body
the initialization code to be stored for later execution
- Deprecated
- Definition Classes
- Source
- App.scala
Concrete fields
The time when the execution of this program started, in milliseconds since 1 January 1970 UTC.
- Source
- App.scala