what are some practical cases of inline classes th...
# announcements
h
what are some practical cases of inline classes though? Doesn’t typealias already kinda do what inline classes do
h
Unsigned values, units
👍 1
m
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.