Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/App

App

scala.App
traitApp extendsDelayedInit

TheApp 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 explicitmain 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 theDelayedInit 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 extendDelayedInit.

In Scala 3, theDelayedInit feature was dropped.App exists only in a limited form that also does not support command line arguments and will be deprecated in the future.

@main methods are the recommended scheme to generate programs that can be invoked from the command line in Scala 3.

@main def runMyProgram(args: String*): Unit = {  // your program here}

If programs need to cross-build between Scala 2 and Scala 3, it is recommended to use an explicitmain method:

object Main {  def main(args: Array[String]): Unit = {    // your program here  }}

Attributes

Source
App.scala
Graph
Supertypes
classObject
traitMatchable
classAny

Members list

Value members

Concrete methods

final protecteddefargs:Array[String]

The command line arguments passed to the application'smain method.

The command line arguments passed to the application'smain method.

Attributes

Source
App.scala
finaldefmain(args:Array[String]):Unit

The main method.

The main method. This stores all arguments so that they can be retrieved withargs and then executes all initialization code segments in the order in which they were passed todelayedInit.

Value parameters

args

the arguments passed to the main method

Attributes

Source
App.scala

Deprecated methods

overridedefdelayedInit(body:=>Unit):Unit

The init hook.

The init hook. This saves all initialization code for execution withinmain. 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 theDelayedInit trait and that do not themselves define adelayedInit method.

Value parameters

body

the initialization code to be stored for later execution

Attributes

Deprecated
[Since version 2.11.0]the delayedInit mechanism will disappear
Definition Classes
Source
App.scala

Concrete fields

The time when the execution of this program started, in milliseconds since 1 January 1970 UTC.

The time when the execution of this program started, in milliseconds since 1 January 1970 UTC.

Attributes

Source
App.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp