DJ Mitchell
11/05/2018, 4:01 PMExpressibleByXXXXLiteral
, so you can create a type and if you pass the correct type of literal as an argument the compiler will automatically lift that literal into the correct type. For instance one nice thing in Kotlin would be to be able to express an inline class
as a literal without having to explicitly initialize a type at the callsite:
inline class UserID(val value: Int) {}
data class User(val userID: UserID) {}
// would love to be able to do this
val user = User(5)
// instead i have to do this
val user = User(UserID(5))
robin
11/05/2018, 4:05 PMDJ Mitchell
11/05/2018, 4:27 PMagrosner
11/05/2018, 4:33 PMDJ Mitchell
11/05/2018, 4:36 PMchr
11/05/2018, 9:01 PMtypealias UserID = Int
data class User(val userID: UserID)
val user = User(5)
DJ Mitchell
11/05/2018, 9:09 PM