EDIT: The main method that is not called in the Scala script is related (in particular, Rigi Jean-Gilles answer). This post provides more details to describe the problem. And the answer (by suish) gives a more practical demonstration to explain the behavior of the Scala team.
Content MiniScalaApp.scala
object MiniScalaApp {
def main(args: Array[String]) = {
println(s"Scala Version: ${scala.util.Properties.scalaPropOrElse("version.number", "unknown")}")
println(new Dinosaur("Tyrannotitan", 4900))
println(new Dinosaur("Animantarx ", 300))
}
class Dinosaur (name:String, weightKG: Int) {
override def toString = f"$name, Weight: $weightKG kg"
}
}
It is executed on the command line:
$ scala /myProject/src/main/scala/MiniScalaApp.scala
Produces the expected output:
Scala Version: 2.11.7
Tiranotitan, Weight: 4900 kg
Animantarx, Weight: 300 kg
However, if the Dinosaur class is located outside the single-element MiniScalaApp object, then the Scala command does not display console output, and an error message does not appear.
object MiniScalaApp {
def main(args: Array[String]) = {
println(s"Scala Version: ${scala.util.Properties.scalaPropOrElse("version.number", "unknown")}")
println(new Dinosaur("Tyrannotitan", 4900))
println(new Dinosaur("Animantarx ", 300))
}
}
class Dinosaur (name:String, weightKG: Int) {
override def toString = f"$name, Weight: $weightKG kg"
}
, , , MiniScalaApp.class
$ scalac /myProject/src/main/scala/MiniScalaApp.scala
$ scala MiniScalaApp
: , Scala -?