Skip to content

Embed video about program entry points #2465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions _overviews/scala3-book/methods-main-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ Scala 3 offers a new way to define programs that can be invoked from the command
@main def hello() = println("Hello, world")
```

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`:
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`:

```bash
$ scalac Hello.scala
```

Then run it with `scala`:

```bash
$ scala hello
$ scala Hello.scala
Hello, world
```

A `@main` annotated method can be written either at the top-level (as shown), or inside a statically accessible object.
In either case, the name of the program is in each case the name of the method, without any object prefixes.

Learn more about the `@main` annotation by reading the following sections, or by watching this video:

<div style="text-align: center">
<iframe width="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>
</div>

### Command line arguments

Expand Down