-2

I am currently learning the Kotlin language.

I want to know what is a Companion Object, and why do we need it?

I think there is a similar concept in Scala.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
  • 4
    https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects – Michael Zajac Dec 16 '16 at 19:43
  • 5
    I don't see how this question asks to recommend an off-site resource. However, this is a duplicate of http://stackoverflow.com/questions/38381748/why-do-we-use-companion-object-as-a-kind-of-replacement-for-java-static-fields and should be closed as such. – yole Dec 17 '16 at 08:35
  • 1
    https://twitter.com/anupcowkur/status/809609624278007810 – Ruslan Dec 30 '16 at 09:00

1 Answers1

2

Members of the companion object can be called by using simply the class name as the qualifier

like a java static

if called Anothrer class's member variable or method you use that companion object