December 2017
Intermediate to advanced
260 pages
7h 34m
English
Companion is a keyword used in Kotlin. An object declaration inside a class can be marked as a companion object. All members of the companion object can be called using the class name directly. Sounds like static!
class MyClass { companion object Factory { fun create(): MyClass = MyClass() } }
Calling can look as follows:
val instance = MyClass.create()
Read now
Unlock full access