Hey :wave: Can someone explain to me the idea of ...
# getting-started
a
Hey 👋 Can someone explain to me the idea of giving a companion object a name. Why should I do it, if the name of the class is used anyway in the end to access the companion object?
Copy code
Members of the companion object can be called simply by using the class name as the qualifier: ...
&&
Copy code
The name of the companion object can be omitted, in which case the name Companion is used: ...
See: https://kotlinlang.org/docs/object-declarations.html#companion-objects
v
Probably interop if you call that code from non-Kotlin code?
e
I think it's partly historical
before Kotlin 1.0 settled on the design, there were unnamed default class objects, declared with
default object
or later
class object
. the lack of a name prevented adding extension functions, so it became possible to name them. later, they were renamed to
companion object
a
Thanks for the answers. 🤝
👌 1