0Pricing
Kotlin Academy · Lesson

Type Aliases

Name complex types.

What Is a Type Alias?

A type alias gives an existing type a new name. It introduces no new type — it is purely a readability tool resolved at compile time.

You declare one with the typealias keyword.

typealias Name = String

fun main() {
    val n: Name = "Alice"
    println(n)
}

Naming Function Types

Function types can be verbose. An alias makes signatures far easier to read.

typealias Handler = (String) -> Unit

fun register(h: Handler) {
    h("event fired")
}

fun main() {
    register { msg -> println(msg) }
}

All lessons in this course

  1. Type Aliases
  2. Inline Value Classes
  3. Use Cases
  4. Limitations
← Back to Kotlin Academy