https://kotlinlang.org logo
a

Alexis Manin

08/03/2021, 5:43 PM
Not sure, but maybe with inline class ? See this modified playground : https://pl.kotl.in/U09d9eWIB
t

TwoClocks

08/03/2021, 5:47 PM
I don't think you can use inline class w/ basic types.. you also can't add/overload operators w/ inline class (at least not the last time I tried, which was a few versions ago).
hmm... actually, I think everything I just said is wrong.
But they can only be immutable, so I'm not sure how to get
+=
to work?
a

Alexis Manin

08/03/2021, 5:59 PM
Look at the playground I attached. It is done in it. However, be careful, because operator overloading in Kotlin is a syntactic sugar for functions, it does not follow math operation priority : https://kotlinlang.org/docs/operator-overloading.html
t

TwoClocks

08/03/2021, 6:30 PM
that'll work. Thanks for the tip on operation order... good to know.
I'm not on 1.5 yet cuz of a bug in the null
?.
operator. Should be fixed in 1.5.30 though, and
JvmInline
doesn't exist in 1.4.x so I'm a little SOL for now. but thanks!
8 Views