Is a value class of a value class still working pr...
# getting-started
m
Is a value class of a value class still working properly? Or will the inner value class end up boxed?
s
@JvmInline value class T(val value: Whatever)
should only box
Whatever
in rare cases like having a
List<T>
. My guess is that you're hitting one of those cases where boxing has always happened. If you think something is off, please provide us with a codesnipped where T is boxed, and we can check if boxing is to be expected or not. https://typealias.com/guides/inline-classes-and-autoboxing/ (current value classes used to be called inline classes, so this article should still apply)
m
@Stephan Schroeder I mean this: https://pl.kotl.in/y71NbusKK
s
ah, value inception ("we have to go deeper"). To be honest the thought of this never crossed my mind. But I'd expect it to work nonetheless. If you simply want different methods in different contexts, you could do extension functions in different packages. But if
Inside
and
Outside
implement different interfaces that this couldn't be replicated with extension functions 🤔 Do you just wonder out of curiousity, or do you have a usecase in mind?
m
Yes, there is an
Offset(x: Float, y: Float)
value class which packs the two floats into a Long as part of Compose UI. I need a similar
Point
class, with different methods, but the same underlying behavior. So I need a different name and a different set of methods for an existing value class. I could of course just copy the source code of
Offset
into my project, but I'd like to avoid that.