Imagine you are creating a project where you defined two classes with same name but different packages and you have to use them at once. Generally, you need to use whole package name dot class name format for the second one. For example, we have a class named ‘courses’ one in “com.gfg.apps” package and another in “com.gfg_practice.apps”, we can use one out of them using simple import and if we want to use second one we have to use full package name like “com.gfg_practie.apps.courses”.
In Kotlin, we have a solution for this named as Type aliases. Type aliases provide an alternate name for the existing types (in our case it is a class).
In our above scenario, we can do:
typealias course = com.gfg_practie.apps.courses
and use the class courses from package “com.gfg_practice.apps” anywhere we want without defining the longer version of it every time we use it.
Kotlin program to demonstrate type aliases –
(Username1, Password1) (Username2, Password2)
Kotlin program to demonstrate –
Positive numbers in the list are: [11, 10, 55, 43]
- Type Aliases vs Inline Classes
- Kotlin Data Types
- Difference between fundamental data types and derived data types
- Hello World program in Kotlin
- Kotlin | Retrieve Collection Parts
- Destructuring Declarations in Kotlin
- DatePicker in Kotlin
- Kotlin labeled continue
- Introduction to Kotlin
- Kotlin Type Conversion
- Kotlin Exception Handling | try, catch, throw and finally
- Kotlin if-else expression
- Kotlin Environment setup for Command Line
- Kotlin constructor
- Kotlin Environment setup with Intellij IDEA
- Kotlin Nested class and Inner class
- Kotlin Variables
- Kotlin Operators
- Kotlin Standard Input/Output
- Kotlin Expression, Statement and Block
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.