(1)不可变类:当你获得这个类的实例的引用之后,你可以改变这个实例的内容。比如:String,BigInteger,BigDecimal,还有基本数据类型的封装类,这些都是不可变类。用实例来调用方法时,不会改变里面的变量的值。代码:

import java.math.BigInteger;
public class BigProblem {
    public static void main(String[ ] args) {
        BigInteger fiveThousand  = new BigInteger("5000");
        BigInteger fiftyThousand = new BigInteger("50000");
        BigInteger fiveHundredThousand = new BigInteger("500000");
        BigInteger total = BigInteger.ZERO;
        total.add(fiveThousand);
        total.add(fiftyThousand);
        total.add(fiveHundredThousand);
        System.out.println(total);
    }
}
View Code

相关文章:

  • 2021-06-17
  • 2022-12-23
  • 2021-10-04
  • 2021-05-22
  • 2021-06-22
  • 2022-12-23
猜你喜欢
  • 2021-08-12
  • 2021-08-09
  • 2021-07-04
  • 2021-11-27
  • 2021-08-03
  • 2021-08-02
  • 2022-01-18
相关资源
相似解决方案