Should I extend java.math.Biginteger and alias tha...
# multiplatform
r
Should I extend java.math.Biginteger and alias that? Edit; hmm that doesnt seem to work out, return types etc are different class because of extending. Don't see how I add this companion object values to the type-alias...
d
You have to remove the expected declaration for NEGATIVE_ONE to use the typealias
r
But if I want to add it? I guess I would not have to do the whole Java implementation of BigInteger myself? Should be some way to just extend it right?
d
This is something I've wondered as well.
r
Ah, I see. Hopefully someone comes around who knows. Otherwise I should just open an issue with YouTrack I guess?
If only this was possible, I would be very close
Copy code
actual typealias BigInteger = java.math.BigInteger
actual val BigInteger.Companion.NEGATIVE_ONE: BigInteger = BigInteger("-1")
d
I suggest that you define them as such in common code.
r
I don't have Java
java.math.BigInteger
in the common code. Also tried extending the companion object on the
java.math.BigInteger
in the JVM code, but it is unknown
d
Well, there is a workaround, it's right in front of you, it's just a little bit ugly
For example you can move NEGATIVE_ONE to a top level extension property and make it expect if you have platform specific implementation
r
How would that look like? I told I tried everything. I'll put it on GitHub later.
Do you mean in the expected class or in the actual (jvm) "class"/typealias. I tried all these variants in the jvm file: https://gist.github.com/RdeWilde/3c76bd09360132dd611dc23cd21b2c2c but ofc none matches the compagnion object (which is unavaible for the extension). I put it in the companion object for efficienty
For now I added this
expect inline fun Int.toBigInteger() : BigInteger
as a workaround. It is syntactical almost same or better
-1.toBigInteger()
but I think it is way less efficient. Not sure if I can check/solve that