测试:
System.out.println(new Long(1000)==new Long(1000));
System.out.println(new Integer(1000)==new Integer(1000)); System.out.println(new Double(1000d)==new Double(1000d)); System.out.println(new Float(1000f)==new Float(1000f)); System.out.println(new Boolean(true)==new Boolean(true)); System.out.println(new Short("400")==new Short("400"));false
falsefalsefalsefalsefalseLong 类型指的是 java.util.Lang 对象,而不是基本类型 long (注意大小写) Java中如果使用 == 双等于比较对象,等于比较的是两个对象的,也就是比较两个对象是否是同一个对象 如果比较两个Long对象值是否相等,则不可以使用双等号进行比较,可以采用如下方式: 1. 使用 equals 方法 Long a = new Long(3); Long b = new Long(3); System.out.println(a.equals(b)); 2. 使用 Long 类型中的 longValue() 方法进行比较,如 Long a = new Long(3); Long b = new Long(3); System.out.println(a.longValue()==b.longValue());