Long a = (long) 1000;
Long b = (long) 1000;
long c = 1000;
long d = 1000;
System.out.println("a == b:" + (a == b));
System.out.println("c == d:" + (c == d));
System.out.println("a.equals(b):" + a.equals(b));
输出:
a == b:false
c == d:true
a.equals(b):true
Long是包装类型,是对象,要用equals方法做比较;
long是基本数据类型,可以直接通过“>”,“==”,“<”作比较