The is and !is operators

To check types we use is as an operator. It is similar to the instanceof operator in Java. But this type check is way smarter than Java.

The following Java code forces us to do type casting even if we have a condition for an instanceof check:

    View view;    if(view instanceof Button){      ((Button) view).setText("Some text");    }

Why double the work? Take a look at the Kotlin is operator. It automatically resolves all button functions for the view object. Now that's called a smart language: 

    val view: View    if (view is Button) {      view.text = "Some text"    }

Get Kotlin Blueprints 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.