https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

Marcin Wisniowski

11/23/2021, 11:35 PM
Is a value class of a value class still working properly? Or will the inner value class end up boxed?
s

Stephan Schroeder

11/24/2021, 8:03 AM
@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

Marcin Wisniowski

11/28/2021, 12:07 PM
@Stephan Schroeder I mean this: https://pl.kotl.in/y71NbusKK
s

Stephan Schroeder

11/29/2021, 7:42 AM
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

Marcin Wisniowski

11/29/2021, 12:23 PM
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.