![]() Type aliases at this level are like a sort of colour-coding on types. ![]() Val password1: PasswordHash = hash("p4ssw0rd") So we can assign freely, but also incorrectly: val userName1: UserName = "user1" However, we cannot use type aliases to constrain parameters: a function accepting a PasswordHash parameter will accept any String value for that parameter. ![]() This can save us having to create wrapper classes like: data class UserName(name: String) An immediately useful consequence of type aliases is that common types can be given aliases that more clearly communicate intent: typealias UserName = String
0 Comments
Leave a Reply. |