August 2017
Intermediate to advanced
440 pages
10h
English
Since version 1.1, Kotlin has had a feature called type alias, which allows us to provide alternative names for existing types. Here is an example of a type alias definition where we have made a list of Users:
data class User(val name: String, val surname: String)
typealias Users = List<User>
This way, we can add more meaningful names to existing data types:
typealias Weight = Double
typealias Length = Int
Type aliases must be declared at the top level. A visibility modifier can be applied to a type alias to adjust its scope, but they are public by default. This means that the type aliases defined previously can be used without any limitations:
val users: Users = listOf( User("Marcin", "Moskala"), User("Igor", "Wojda") ) fun ...Read now
Unlock full access