Skip to content

Commit 4a1e511

Browse files
committed
Add Scala 2 / Scala 3 syntax to the Getting Started with Intellij tutorial
1 parent f898427 commit 4a1e511

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

_getting-started/intellij-track/getting-started-with-scala-in-intellij.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,54 @@ take a few minutes but subsequent projects can use the same SDK.
4242
1. On the **Project** pane on the left, right-click `src` and select
4343
**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.
4444
1. Name the class `Hello` and change the **Kind** to `object`.
45-
1. Change the code in the class to the following:
45+
1. Change the code in the file to the following:
46+
47+
{% tabs hello-world-entry-point class=tabs-scala-version %}
48+
49+
{% tab 'Scala 2' for=hello-world-entry-point %}
4650

4751
```
4852
object Hello extends App {
4953
println("Hello, World!")
5054
}
5155
```
5256

57+
{% endtab %}
58+
59+
{% tab 'Scala 3' for=hello-world-entry-point %}
60+
61+
```
62+
@main def hello(): Unit =
63+
println("Hello, World!")
64+
```
65+
66+
In Scala 3, you can remove the object `Hello` and define a top-level method
67+
`hello` instead, which you annotate with `@main`.
68+
69+
{% endtab %}
70+
71+
{% endtabs %}
72+
5373
## Running it
74+
75+
{% tabs hello-world-run class=tabs-scala-version %}
76+
77+
{% tab 'Scala 2' for=hello-world-run %}
78+
5479
* Right click on `Hello` in your code and select **Run 'Hello'**.
5580
* You're done!
5681

82+
{% endtab %}
83+
84+
{% tab 'Scala 3' for=hello-world-run %}
85+
86+
* Right click on `hello` in your code and select **Run 'hello'**.
87+
* You're done!
88+
89+
{% endtab %}
90+
91+
{% endtabs %}
92+
5793
## Experimenting with Scala
5894
A good way to try out code samples is with Scala Worksheets
5995

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

65101
```
66-
def square(x: Int) = x * x
102+
def square(x: Int): Int = x * x
67103
68104
square(2)
69105
```
70106

71107
As you change your code, you'll notice that it gets evaluated
72-
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.
108+
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.
73109

74110
## Next Steps
75111

0 commit comments

Comments
 (0)