Checking for non-null types

This is similar to the previous one, but it checks directly for the type:

if (nullableCupcake is Cupcake) {
nullableCupcake.eat()
}

It also works with when:

when (nullableCupcake) {
is Cupcake -> nullableCupcake.eat()
}

Both options, checking for null and non-null types, are a little bit verbose. Let's check other options.

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

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