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
- Type Aliases
- Inline Value Classes
- Use Cases
- Limitations