Klitos Kyriacou
07/28/2023, 8:31 AMKlitos Kyriacou
07/28/2023, 8:32 AM@JvmInline
value class SelfIncrementingLong(private var value: Long) {
fun getAndIncrement() = value++
}
...
val offset = SelfIncrementingLong(0)
Now the only way I can get the value is using getAndIncrement.
This need is very specific and local to this function, so I didn't want to create a new class for it. It's much more concise to use an anonymous class:
val offset = object {
private var value: Long = 0
fun getAndIncrement() = value++
}
But now offset is boxed. Is it possible to write an anonymous object but have it as a @JvmInline value class? If not, is there an existing proposal for such a thing?Youssef Shoaib [MOD]
07/28/2023, 8:47 AMYoussef Shoaib [MOD]
07/28/2023, 8:47 AMinline fun SelfIncrementingLong.getValue
which calls getAndIncrement
Youssef Shoaib [MOD]
07/28/2023, 8:48 AMKlitos Kyriacou
07/28/2023, 8:59 AMinline fun SelfIncrementingLong.getValue
?Youssef Shoaib [MOD]
07/28/2023, 9:01 AMval offset by SelfIncrementingLong(0)
and every time offset
is used, the long would be incremented