Help needed for scala classes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help needed for scala classes

Amrit Pal Singh
Hello, I am new to SCALA..The doubt I am having is while running my scala class from eclipse its doesnt give option like RUN AS SCALA APPLICATION.
As per my understanding the class needs a main method but after declaring the main method its still  not giving me the option of running as a main method.
On the other hand when i declare the main method under  scala object its give me the option,why the above problem is happening with me.?
Please guide me the  right path what approach i should follow.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help needed for scala classes

Jasper-M
Hi,

To run a program on the JVM, that program needs to have entry point that the JVM can execute: a public static void main(String[] args) method. The reason it has to be static is because you don't have to first create a new object to call a static method.
Scala doesn't have static methods, but methods in singleton objects are compiled to JVM static methods. So in scala your main method needs to be inside of an object, not a class:

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

Kind regards,
Jasper

Op woensdag 14 december 2016 14:25:26 UTC+1 schreef Amrit Pal Singh:
Hello, I am new to SCALA..The doubt I am having is while running my scala class from eclipse its doesnt give option like RUN AS SCALA APPLICATION.
As per my understanding the class needs a main method but after declaring the main method its still  not giving me the option of running as a main method.
On the other hand when i declare the main method under  scala object its give me the option,why the above problem is happening with me.?
Please guide me the  right path what approach i should follow.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help needed for scala classes

Amrit Pal Singh
In reply to this post by Amrit Pal Singh
Thanks for the reply.It means for running a scala class we have to create the instance of that class in OBJECT .

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help needed for scala classes

Donald McLean-3

On Wed, Dec 14, 2016 at 12:20 PM, Amrit Pal Singh <[hidden email]> wrote:
Thanks for the reply.It means for running a scala class we have to create the instance of that class in OBJECT .

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Family photographs are a critical legacy for
ourselves and our descendants. Protect that
legacy with a digital backup and recovery plan.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.