Type aliases provide alternative names for existing types. If the type name is too long you can introduce a different shorter name and use the new one instead.
It's useful to shorten long generic types. For instance, it's often tempting to shrink collection types:
You can provide different aliases for function types:
You can have new names for inner and nested classes:
Type aliases do not introduce new types. They are equivalent to the corresponding underlying types. When you add
typealias Predicate<T> and use
Predicate<Int> in your code, the Kotlin compiler always expands it to
(Int) -> Boolean. Thus you can pass a variable of your type whenever a general function type is required and vice versa: