Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "main method should be static" occurs if object name is "Statistic" in Scala

Tags:

scala

the code below:

object Statistic{
    def main(args:Array[String]):Unit={}
}

will report error "main method should be static"

but if object name is not "Statistic" like below,no error reported:

object Statistics{
    def main(args:Array[String]):Unit={}
}

and i'm using IDEA for Scala

like image 969
郭志良 Avatar asked Feb 06 '23 12:02

郭志良


2 Answers

The problem is with Intellij run configurations. Sometimes it fails to adapt to changes in the code. Just delete the run configuration that creates the problem and you will see it works also with Statistic.

like image 119
Chobeat Avatar answered Feb 08 '23 01:02

Chobeat


Its an IntelliJ quirk. In run configuration remove the dot in front of the main class. You can find it in: Run -> Edit Configurations... -> Main class

like image 42
sparker Avatar answered Feb 08 '23 00:02

sparker