© Peter Späth 2019
Peter SpäthLearn Kotlin for Android Developmenthttps://doi.org/10.1007/978-1-4842-4467-8_4

4. Classes and Objects: Extended Features

Peter Späth1 
(1)
Leipzig, Germany
 

This chapter covers some extended object orientation features that are not necessary for a program to work, but nevertheless improve readability and expressiveness. The chapter presumes that you have read Chapter 2. We also use the NumberGuess sample app from Chapter 2.

Anonymous Classes

Inside your coding in some instances you might want to create a one-time implementation of an interface or a one-time subclass of some class. While in Kotlin, it is possible to write
class A : SomeInterface {
    // implement interface functions ...
}
val inst:SomeInterface = A()
// use ...

Get Learn Kotlin for Android Development: The Next Generation Language for Modern Android Apps Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.