Probably being thick... I need to construct a boxe...
# getting-started
r
Probably being thick... I need to construct a boxed inline class from Java (well, Groovy, but kind of the same thing...) in order to put it in a list. I can't currently work out how?
e
it's not quite the same thing, since Groovy can more easily access things that Java can't
Copy code
$ groovysh -cp kotlin-stdlib-1.8.10.jar
groovy:000> kotlin.UInt."box-impl"(-1)
===> 4294967295
but perhaps reconsider if you have to do this. why do you have a list of boxed inline classes and why does it need to be used outside of Kotlin?
r
I've got a Kotlin function that returns
List<ValueType>
and I need to test it in Spock, hence Groovy calling Kotlin. I'm not sure if I can avoid them being boxed while keeping the Kotlin type... all I'm doing is
listOf("1", "2").map { ValueType(it) }.toSet()
and that seems to box them.
But thanks, that's a good point on groovy being able to call members with weird names, that works!
e
you could build your own specialized
ValueTypeSet
(as
UIntArray
does for
UInt
) that is represented by a
Set<String>
or whatever the
val
you're wrapping is
but that'll be pretty awkward, at least until https://youtrack.jetbrains.com/issue/KT-44654
r
Honestly I could probably just use a data class - it's not like the memory is actually an issue, I just quite like the idea of compiler enforced type aliases!