0Pricing
Kotlin Academy · Lesson

is and as Operators

Type checks and casts.

Checking and Casting Types

Kotlin offers two operators for working with types at runtime:

  • is checks whether a value is of a type
  • as casts a value to a type

Both have safe variants you will learn here.

The is Operator

is returns a boolean telling you if a value matches a type.

It is the foundation for smart casts.

fun main() {
    val x: Any = "hello"
    println(x is String)
    println(x is Int)
}

All lessons in this course

  1. when as Expression
  2. Smart Casts
  3. is and as Operators
  4. Exhaustive when
← Back to Kotlin Academy