Why the "main method must be static" occurs if the name of the "Statistics" object in Scala

code below:

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

will report an error "the main method must be static"

but if the name of the object is not “Statistical,” as indicated below, no error is reported:

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

and I use IDEA for Scala

+4
source share
3 answers

The problem is the Intellij run settings. Sometimes it cannot adapt to changes in the code. Just remove the startup configuration that creates the problem, and you will see that it also works with Statistic.

+6
source

. . : Run → Edit Configurations... →

+2

Usually I try to reorganize the name of an object to make Intellij forget!

0
source

Source: https://habr.com/ru/post/1664142/


All Articles