拆箱和装箱下的特殊情况==比较

自动拆箱和自动装箱
  1. static Integer a = 30;
    static Integer b = 30;
    a==b
    如果在不同的对象中;且超出缓存范围(-128~~127)即为false
    普遍情况下equal都根据值判断,没有其他误差
        package com.catches;

        public class Demo06 {
            static Integer a = 300;
            static Integer b = 300;
            public static void main(String[] args) {

                Integer c = new Integer(30);
                Integer d = new Integer(30);
                /*System.out.println("equals"+(a.equals(b)));//true
                System.out.println("=="+(a==b));//true
                System.out.println("equals"+c.equals(d));//true*/
                System.out.println("==***"+(a==b));//false
                System.out.println(c);
                System.out.println(d);
            }
        }

posted @ 2022-04-09 14:43  爱豆技术部  阅读(39)  评论(0)    收藏  举报