More companions
You are limited to having only one companion object in your class:
class A { companion { } companion { } }
But you can have as many objects in your class as you want:
class A { object B { } object C { } }
This is sometimes used to produce namespacing. Namespacing is important because it provides you with better naming conventions. Think about having cases when you created classes such as SimpleJsonParser
, which inherits from JsonParser
, which inherits from Parser
. You could convert this structure to Json.Parser
, for example, which is much more concise and practical, as Kotlin code should be.