July 2018
Intermediate to advanced
336 pages
9h 23m
English
An object declaration inside a class can be specified as a companion object of it, just like in the following code:
class Bean { companion object Factory { fun create() : Bean = Bean(); }}
This means that methods of object declaration inside can be invoked by just specifying the name of the outer class, as follows:
var bean = Bean.create();
A companion object is initialized when the outer class enclosing it is loaded similarly to a static initializer in Java.
Read now
Unlock full access