Skip to main content
Browse topics

Type Aliases in Kotlin

2 min read Updated June 30, 2026
Share

Introduction

Type Aliases is a fundamental concept every Kotlin developer should understand. Type aliases and destructuring declarations make Kotlin code more readable and expressive without changing runtime behaviour.

A type alias gives an existing type a shorter or clearer name. In this tutorial you will learn the syntax, walk through a complete example program, study the sample output, and review best practices so you can apply the concept confidently in your own projects.

Definition

  • A type alias gives an existing type a shorter or clearer name.
  • Aliases do not create a new type — they are compile-time shortcuts.
  • They are useful for long generic signatures and domain-specific naming.

Syntax

kotlin
typealias UserId = String
typealias ScoreMap = Map<String, Int>

Type Aliases in Kotlin Example Program in Kotlin

kotlin
typealias UserId = String
typealias ScoreMap = Map<String, Int>

fun main() {
    val id: UserId = "user-101"
    val scores: ScoreMap = mapOf("math" to 95, "science" to 88)
    println("User $id scores: $scores")
}

Sample Output

plaintext
User user-101 scores: {math=95, science=88}

When to use

Use type aliases for long generic types; use destructuring when unpacking data classes or pairs in loops.

How it works

  1. The program starts with a main function — the entry point that runs when you execute the file.

  2. A type alias gives an existing type a shorter or clearer name.

  3. Run the program in IntelliJ IDEA, Android Studio, or with the Kotlin command-line compiler (kotlinc / kotlin). Compare your console output with the sample output shown below.

Best Practices

Common Mistakes

Key Points

  • A type alias gives an existing type a shorter or clearer name.
  • Aliases do not create a new type — they are compile-time shortcuts.
  • They are useful for long generic signatures and domain-specific naming.
  • Test the example locally and verify the output matches the sample.
  • Experiment by changing input values to see how behaviour changes.

Notes

  • Semicolons at the end of statements are optional in Kotlin.

Frequently Asked Questions

What is Type Aliases in Kotlin?
A type alias gives an existing type a shorter or clearer name.
When should I use Type Aliases?
Use type aliases for long generic types; use destructuring when unpacking data classes or pairs in loops.
How is Type Aliases different from Java?
They are useful for long generic signatures and domain-specific naming.
How do I practice this topic?
Copy the example program into IntelliJ IDEA or Android Studio, run it, then modify values or add print statements to confirm your understanding.

Related tutorials

Search tutorials