问题描述:

I have used Scala but I worked with objects but now I have to use classes. I am creating a scala class in a package, however, when I try to run it, it asks me to choose between Scala Applet or Scala Application and none of them work. Anybody has an idea on how to fix this problem? And do you declare a main method inside a class (like in objects) ?

网友答案:

For running your application you need to have App extended object or an object with main method. It is nice that you are using classes. But the entry point of your code must be an object with main method or ( App extended )

So use your classes to build the application but start your application from an object.

网友答案:
case class Test(val x: Int);

object Main extends App {
   override def main(args: Array[String]): Unit = {
      val x = Test(5);
      println("this is the main method");
      println(x);
   }
}

In the JVM world, the main method in the entry point to an application. In general, the main method is where you start your various components, the threads/executors that run them etc.

相关阅读:
Top