• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Can main method of Scala be called without using Object keyword

 
Ranch Hand
Posts: 2542
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The condition  for calling main method is that it should be public and static. In Scala we have public modifier then why can't we call the main method without Object keyword?

Thanks
 
Saloon Keeper
Posts: 13367
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean that you can't run an application without main being inside an object?

Tell me, what command would you use to run the application if you didn't have an object with a name?
 
Monica Shiralkar
Ranch Hand
Posts: 2542
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant running Scala main method requires Object Keyword (singleton class). Can it use Class keyword like Java?
 
Stephan van Hulst
Saloon Keeper
Posts: 13367
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like something you can find out really easily by trying it out.
 
Sheriff
Posts: 8094
569
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not exactly sure what is the key question in this thread, but you can avoid declaring main() method yourself and simply write this as an app starting point:
 
Stephan van Hulst
Saloon Keeper
Posts: 13367
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Monica was asking if you can start a program by calling a main() method in a class, instead of a singleton object, to which I replied she can find it out by trying it.
 
Monica Shiralkar
Ranch Hand
Posts: 2542
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I will try out with class and try to understand what problem exactly occurs.
 
Monica Shiralkar
Ranch Hand
Posts: 2542
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I tried running  the main method from a Class instead of Object (singleton class),  the option "Run as Scala Application"  is no more there.
 
Stephan van Hulst
Saloon Keeper
Posts: 13367
295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There you go.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic