diesieben07
01/09/2019, 1:21 PMtypealias
😉Marc Knaup
01/09/2019, 1:28 PMval emaiAddress = username
inline class: error
typealias: no errordiesieben07
01/09/2019, 1:31 PMdiesieben07
01/09/2019, 1:32 PMMarc Knaup
01/09/2019, 1:33 PMA
where type B
is expected.
I can still use for example all String
mutations on A
and B
(if they’re both wrapping a String
) without even temporarily losing the type safety.diesieben07
01/09/2019, 1:34 PMString
methods on InlineClass
. Is that not using InlineClass
where String
is expected?Marc Knaup
01/09/2019, 1:36 PMtransparent inline class A(val raw: String)
val a = A("test")
val x: String = a // won't work
val a2: A = a.trim() // works, only modifies .raw, result is still an A
diesieben07
01/09/2019, 1:37 PMcbruegg
01/09/2019, 1:39 PMtransparent inline class
would not be assignable to a variable of the underlying type, but magically it can become the receiver for a method on that type? Seems very inconsistent to me.Marc Knaup
01/09/2019, 1:40 PMString
everywhere (no safety at all) and an inline class
(completely isolated) which requires plenty of wrapping and unwrapping for even basic operations like a.length
Marc Knaup
01/09/2019, 1:43 PMraulraja
01/09/2019, 2:49 PMraulraja
01/09/2019, 2:59 PMval a: A = "test"
In this case having an inline class as proof of relationship between A
and String
hides that there is a magic type conversion in call sites and causes confusion.
We already have delegates acting the way you propose, the issue is that String
is final. But dispatching method to a value in a class is something Kotlin already does with by
so I think a good controlled transparent
feature is not bad and inline with Kotlin if it disallows implicit connversions