(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); } }