基本类型与引用类型的 比较基本类型如 int、double使用比较时直接比较数值是否相等。引用类型如 String、自定义类使用比较时比较的是对象的内存地址是否相同。Integer 的创建方式差异Integer.valueOf()会使用缓存池默认缓存 -128 到 127 的 Integer 对象多次调用可能返回同一对象的引用。new Integer()每次都会创建新的对象即使数值相同地址也不同。包装类与基本类型的 比较包装类如 Integer与基本类型如 int用比较时包装类会自动拆箱为基本类型直接比较数值。包装类之间的值比较包装类之间比较值时应使用equals()方法避免使用因比较的是地址而非数值。例如Integer a 100; Integer b 100; System.out.println(a b); // true缓存池作用 System.out.println(a.equals(b)); // true Integer c 200; Integer d 200; System.out.println(c d); // false超出缓存范围 System.out.println(c.equals(d)); // true