February 2018
Intermediate to advanced
350 pages
7h 35m
English
In Kotlin, objects are a type, therefore they can have functions, including extension functions (among other things, such as extending interfaces and others).
We can add a buildBridge extension function to the object, Builder:
object Builder {}fun Builder.buildBridge() = "A shinny new bridge"
We can include companion objects. The class Designer has two inner objects, the companion object and Desk object:
class Designer { companion object { } object Desk { }}fun Designer.Companion.fastPrototype() = "Prototype"fun Designer.Desk.portofolio() = listOf("Project1", "Project2")
Calling this functions works like any normal object member function:
Designer.fastPrototype()Designer.Desk.portofolio().forEach(::println) ...
Read now
Unlock full access