==和equals与自动装箱的经典面试题
/**
* @Author:ZMR
* @create 10:08 2021/4/7
*
* 面试题
*/
public class TestD {
public static void main(String[] args) {
int a = 10;
Integer b = 10;
System.out.println(a==b); //T
System.out.println(b.equals(a)); //T 使用 equals比较两个对象是否相同,这个位置存在自动装箱
Integer a2 = new Integer(10);
Integer b2 = new Integer(10);
System.out.println(a2==b2); //F
System.out.println(a2.equals(b2)); //T
Integer a3 = 10; //隐藏了自动装箱
Integer b3 = 10;
System.out.println(a3==b3); //T
System.out.println(a3.equals(b3)); //T
Integer a4 = 190; //new Integer(190);
Integer b4 = 190; //new Integer(190);
System.out.println(a4==b4); //F
System.out.println(a4.equals(b4)); //T
}
}