Boolean

Boolean内部维护了两个常量:

public static final Boolean TRUE = new Boolean(true);
public static final Boolean FALSE = new Boolean(false);

所以对于Boolean a = true; Boolean b = true;a == b是得到true的。

Integer

Integer对一段范围内的数字有个缓存:IntegerCache.low ~ IntegerCache.high
如果数字在这个范围内,两个integer ==是返回true的;否则就会new一个对象返回,肯定是不相等的。
IntegerCache的low是固定死的-128,high默认127,可以通过这个配置修改-XX:AutoBoxCacheMax

Short、Long

和Integer差不多,但是它们的high是固定的127。

参考

Java原生类型包装类初解析