October 2019
Intermediate to advanced
434 pages
11h 54m
English
Kotlin allows us to define interface properties as well. An interface property can include a value assignment or can include just the property definition, in which case an implementing class is required to either provide a value or to be marked abstract. In the following example, we've added an id property to the GameObject interface:
interface GameObject { val id: String fun update(currentTime: Long)}
Our Player class is now required to either be marked abstract or to override the id property. In this case, id is overridden using a single expression:
class Player : GameObject { override val id = "playerId" override fun update(currentTime: Long) { // add logic }}
It's also possible to override an interface ...
Read now
Unlock full access