There's no trivial way to make a `value class` exp...
# getting-started
r
There's no trivial way to make a
value class
expose all its value's members at the top level is there?
s
Sure, change it from a
value class
to a
typealias
😉😄
r
I want the type safety.
s
The only other way I can think of is if the value implements an interface, you should be able to use interface delegation on the value class: https://kotlinlang.org/docs/whatsnew17.html#allow-implementation-by-delegation-to-an-inlined-value-of-an-inline-class
r
It doesn't, but it might be an idea to pull an interface out to get the behaviour. Bit more work than I was hoping for though.
p
I wonder if a simple plugin using https://square.github.io/kotlinpoet or KSP would work to generate some extension properties to directly expose the properties of the boxed value might work
r
Thanks, I was just checking that there was nothing out of the box I was ignorant of - I can always delegate manually.
y
A feature proposal could be to have `transparent value class`es that pretend like they're subtypes of their underlying value but without being allowed to
override
any of its methods or properties (potentially even including
toString
for consistency's sake). I made a similar feature proposal a while back, but it was very speculative and under-specified. Transparent value classes could also be a good gateway for Kotlin to get into refined types, but that's a whole another story.
👍 1