Skip to content

Add Scala 2 / Scala 3 syntax to the Getting Started with Intellij tutorial #2454

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 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,54 @@ take a few minutes but subsequent projects can use the same SDK.
1. On the **Project** pane on the left, right-click `src` and select
**New** => **Scala class**. If you don't see **Scala class**, right-click on **HelloWorld** and click on **Add Framework Support...**, select **Scala** and proceed. If you see **Error: library is not specified**, you can either click download button, or select the library path manually. If you only see **Scala Worksheet** try expanding the `src` folder and its `main` subfolder, and right-click on the `scala` folder.
1. Name the class `Hello` and change the **Kind** to `object`.
1. Change the code in the class to the following:
1. Change the code in the file to the following:

{% tabs hello-world-entry-point class=tabs-scala-version %}

{% tab 'Scala 2' for=hello-world-entry-point %}

```
object Hello extends App {
println("Hello, World!")
}
```

{% endtab %}

{% tab 'Scala 3' for=hello-world-entry-point %}

```
@main def hello(): Unit =
println("Hello, World!")
```

In Scala 3, you can remove the object `Hello` and define a top-level method
`hello` instead, which you annotate with `@main`.

{% endtab %}

{% endtabs %}

## Running it

{% tabs hello-world-run class=tabs-scala-version %}

{% tab 'Scala 2' for=hello-world-run %}

* Right click on `Hello` in your code and select **Run 'Hello'**.
* You're done!

{% endtab %}

{% tab 'Scala 3' for=hello-world-run %}

* Right click on `hello` in your code and select **Run 'hello'**.
* You're done!

{% endtab %}

{% endtabs %}

## Experimenting with Scala
A good way to try out code samples is with Scala Worksheets

Expand All @@ -63,13 +99,13 @@ A good way to try out code samples is with Scala Worksheets
3. Enter the following code into the worksheet:

```
def square(x: Int) = x * x
def square(x: Int): Int = x * x

square(2)
```

As you change your code, you'll notice that it gets evaluated
in the right pane. If you do not see a right pane, right click on your Scala worksheet in the Project pane, and click on Evaluate Worksheet.
in the right pane. If you do not see a right pane, right-click on your Scala worksheet in the Project pane, and click on Evaluate Worksheet.

## Next Steps

Expand Down