Why does Scala start with an object main method instead of a static main class method?
In Java, a program is run from the main static method of a class. But in Scala it starts with the main method of the object.
Does anyone know the rationality of such a design?
Scala also provides a trait App
that can replace a method main
if the object extends that trait. Does anyone have any ideas as to which one is ( App
or main
) the preferred way?
Thank!
source to share
I'm always extending App
in my main class and don't know the reason why anyone would want to write an explicit main method - except perhaps for compatibility with some other code that was too fussy about such things. Whenever I see an explicit main method in Scala, I wonder if the code is very old (pre-existing App
) or if the author was new to Scala.
But this question is mostly related to why the Scala designers left out static methods. You can find this question on how static members are not object oriented .
source to share