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. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.122.127