I'm trying to run a simple Scala snippet,
package example
class HelloWorld extends App {
println("Hello world")
}
in the IntelliJ IDE with Scala installed. However, the "Run" button appears to be grayed out, and I also don't see it in the context menu (not shown in the screen grab below).
In accordance with the answer of Unable to run Java code with Intellij IDEA, the code is in the src
folder which is marked blue. (I've also tried marking it as a 'tests' folder but to no avail). What am I missing?
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.
HelloWorld
should be object
, not class
:
package example
object HelloWorld extends App {
println("Hello world")
}
For more info about singleton objects, you can see this chapter of "Programming in Scala" book and this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With