java.math.MutableBigInteger
只能从包内部获得。它继承自 java.lang.Object
,只有一个子类 (SignedMutableBigInteger
),只能在包内使用。
最佳答案
/**
* A class used to represent multiprecision integers that makes efficient
* use of allocated space by allowing a number to occupy only part of
* an array so that the arrays do not have to be reallocated as often.
* When performing an operation with many iterations the array used to
* hold a number is only reallocated when necessary and does not have to
* be the same size as the number it represents. A mutable number allows
* calculations to occur on the same number without having to create
* a new number for every step of the calculation as occurs with
* BigIntegers.
*
* @see BigInteger
* @version 1.12, 12/19/03
* @author Michael McCloskey
* @since 1.3
*/
Source .
我猜 MutableBigInteger 在内部用于 BigInteger 繁重的计算,这些计算会因频繁的重新分配而减慢速度。我不确定为什么它不作为 java.math 的一部分导出。也许对可变值类有些厌恶?
澄清“可变”:
标准 BigInteger 在其整个生命周期内只有一个值,给定两个 BigInteger 引用“a”和“b”,“a+b”将始终产生一个具有相同值的新 BigInteger。假设该值为 4。
使用 MutableBigInteger,“a+b”最初可能产生 4,但在未来某个时间点产生 8、16、32 或任何其他数字,因为其他代码更改了所引用对象的值(也称为变异)通过“a”和“b”。因此,Java 中的大多数(可能是全部)值类型(Character、Short、Long、Integer、BigInteger、BigDecimal、Float、Double,甚至 String)都是不可变的。
关于java - java.math.MutableBigInteger 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/890968/