February 2018
Intermediate to advanced
350 pages
7h 35m
English
All types in Kotlin extend from the Any type (hold on a second, actually this isn't true but for the sake of the explanation, bear with me).
Every class and interface that we create implicitly extends Any. So, if we write a method that takes Any as a parameter, it will receive any value:
fun main(args: Array<String>) { val myAlmondCupcake = Cupcake.almond() val anyMachine = object : Machine<Any> { override fun process(product: Any) { println(product.toString()) } } anyMachine.process(3) anyMachine.process("") anyMachine.process(myAlmondCupcake) }
What about a nullable value? Let's have a look at it:
fun main(args: Array<String>) { val anyMachine = object : Machine<Any> { override fun process(product: Any) { println(product ...
Read now
Unlock full access