1.

What is a purpose of Companion Objects in Kotlin?

Answer»

In Kotlin, if you NEED to write a code for a function that can be CALLED without a class instance but it NEEDS access to the INTERNALS of a class, you can use a companion object DECLARATION in that specific class.

Example

class EventsManager {
    companion object FirebasesManager {     
    }  
}
val firebasesManager = EventsManager.FirebasesManager



Discussion

No Comment Found