chalup
08/31/2018, 3:05 PMInline classes are similar to type aliases, but they are not assignment-compatible with the underlying value type, so you cannot assign a String to a variable of type Name, and vice versa.I'm wondering about the
Name
to String
conversion part, i.e. let's say we have:
inline class Name(val value: String)
val name = Name("Jerzy")
// old API that still uses raw String
fun greet(val name: String)
// the way we'd call the method with Name
greet(name.value)
I'm curious what are the negative aspects of automatic unwrapping, i.e. allowing the greet(name)
call? I can't think of anything being terribly broken by this change, and it would allow gradual migration from bunch of String
params to wrapped classes.arocnies
08/31/2018, 3:52 PMvalue
property or that property is private?karelpeeters
08/31/2018, 4:01 PMUInt
its value interpreted as an Int
isn't really meaningful.karelpeeters
08/31/2018, 4:02 PMchalup
08/31/2018, 4:16 PMprivate
property use case. I assumed the most common use case would be simple wrapper classes, and that calling .value
or some unwrapping function would be unnecessary boilerplate.chalup
08/31/2018, 4:21 PMUInt
and a stronger version of type alias.arocnies
08/31/2018, 4:23 PMchalup
08/31/2018, 4:32 PMName
where Password
is required and vice versa. I'd like to have automatic unwrapping onlykarelpeeters
08/31/2018, 4:33 PMchalup
08/31/2018, 4:37 PMkarelpeeters
08/31/2018, 4:38 PMchalup
08/31/2018, 4:40 PMchalup
08/31/2018, 6:55 PM