Skip to content

Kotlin Object VS Kotlin Companion Object

Devrath edited this page Aug 24, 2022 · 1 revision
  • In terms of life-cycle there is no difference between the two.
  • INITIALIZATION
    • Objects are thread-safe and lazily initialized, It is initialized when it's accessed for the first time.
    • Companion Object is initialized like static members when the container class is initialized for the first time.

If we want to create a singleton we can use object class, If we want to provide some static essence for the class then we use companion object.

Clone this wiki locally