You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _overviews/scala3-book/methods-main-methods.md
+6-8Lines changed: 6 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -14,23 +14,21 @@ Scala 3 offers a new way to define programs that can be invoked from the command
14
14
@main defhello() = println("Hello, world")
15
15
```
16
16
17
-
Just save that line of code in a file named something like *Hello.scala*---the filename doesn’t have to match the method name---and compile it with `scalac`:
17
+
Just save that line of code in a file named something like *Hello.scala*---the filename doesn’t have to match the method name---and run it with `scala`:
18
18
19
19
```bash
20
-
$ scalac Hello.scala
21
-
```
22
-
23
-
Then run it with `scala`:
24
-
25
-
```bash
26
-
$ scala hello
20
+
$ scala Hello.scala
27
21
Hello, world
28
22
```
29
23
30
24
A `@main` annotated method can be written either at the top-level (as shown), or inside a statically accessible object.
31
25
In either case, the name of the program is in each case the name of the method, without any object prefixes.
32
26
27
+
Learn more about the `@main` annotation by reading the following sections, or by watching this video:
33
28
29
+
<divstyle="text-align: center">
30
+
<iframewidth="560"height="315"src="https://www.youtube.com/embed/uVMGPrH5_Uc"title="YouTube video player"frameborder="0"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"allowfullscreen></iframe>
0 commit comments