I am implementing a faster implementation BigInt, and I'm not sure how far I have to go in order to interact with the underlying platform.
Today it BigIntjust wraps BigInteger, and the value BigIntegerjust returns the wrapped value:
class BigInt(val bigInteger: BigInteger) ...
Since I am not wrapping a Java type, I would need to do something like
final class BigInt private(final val signum: Int,
final private[math] val arr: Array[Int])
def bigInteger: java.math.BigInteger = {
val ctor = classOf[java.math.BigInteger]
.getDeclaredConstructor(classOf[Array[Int]], classOf[Int])
ctor setAccessible true
ctor.newInstance(arr, signum.asInstanceOf[Object])
}
...
}
Could this cause problems or is there a better way to do this?
source
share