scalastaticjvmprogram-entry-point

why the scala programe created by singleton object doesnt require a static main method?


I am new to scala ,and worked with java previosly.On studying i found that we can create a singleton object like given below

object Hello{
    def main(a:Array[String]){
        println("hello user")
    }
}

If Scala uses JVM then why the scala programe created by singleton object doesnt require a static main method?

I know its a very basic question but i am a beginner. and also if anybody can suggest me some docs online to study scala. Thanks in advance.


Solution

  • Methods of singleton objects get translated into static methods (among other stuff). So you actually do have the equivalent of a static main method.

    Have a look at the generated class files and you will see.