https://kotlinlang.org logo
Title
h

Hamza

10/30/2018, 12:58 AM
what are some practical cases of inline classes though? Doesn’t typealias already kinda do what inline classes do
h

hudsonb

10/30/2018, 1:10 AM
Unsigned values, units
👍 1
m

Mike

10/30/2018, 1:23 AM
Refer to docs https://kotlinlang.org/docs/reference/inline-classes.html#inline-classes-vs-type-aliases
However, the crucial difference is that type aliases are assignment-compatible with their underlying type (and with other type aliases with the same underlying type), while inline classes are not.
typealias MoneyTA = BigDecimal inline class MoneyIC(val BigDecimal) I can pass a BigDecimal to a function that takes MoneyTA. I CAN’T pass BigDecimal to a function that takes MoneyIC. Bottom-line: inline classes provide for stronger typing of wrapped class.