Topic Companion Object and Companion Class in Scala
Git Sample CompanionObjectTest.scala

  • Java provides static keyword. Scala lacks static or class access. Companion Object gives you this opportunity

  • Inside a Scala program, when you have a class and an object, with same names, underlying class becomes Companion Class and respective object is called Companion Object

  • Both Companion Class and its Companion Object must be defined in the same source file

results matching ""

    No results matching ""