Type Aliases in Kotlin


Type Aliases in Kotlin

In a project, we may declare variables of the same data type more than once, declare the same variable as the API Response class type on Android, or use the same function again and again without making our code readable. Type aliases give an alternative name to existing types (in our case, it's a class).

A type alias allows renaming an existing data type into your program. After declaring a kind of alias, the alias can be used to replace the current type throughout the program. Type alias does not create new varieties, and they give a new name to the existing type.

The Bytecode Representation

Type aliases are mere archetypes of the source code, and therefore, they do not introduce any new types in runtime. For example, wherever we use a credit card example, the Kotlin compiler translates it into a string. The generated bytecodes will be reviewed to check if this translation is working.