1

As we know we don't have static methods in scala. If we have to achieve that taste we declare that class as object. But the problem is that when we declare class as object then all methods present in that object becomes static. And in class all methods all non-static. What I want is that to have static as well as non static methods in the same class, Is it possible? Definitely it would be possible but how??????

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user3181531
  • 9
  • 1
  • 2
  • Which leads you to this: http://programmers.stackexchange.com/questions/179390/what-are-the-advantages-of-scalas-companion-objects-vs-static-methods – Guy Schalnat Jul 16 '15 at 04:14

1 Answers1

3

To do what you are trying do in Scala you create an object and a class of same name. Put static in object and instance members in Class version of it. This object is called a companion object.

shanmuga
  • 4,329
  • 2
  • 21
  • 35
Shahzeb
  • 4,745
  • 4
  • 27
  • 40