long a=127;
long b=123456;
long c=123456;
Long d=123456L;
Long e=123456L;
Long f=127L;
Long g=127L;
Long h= new Long(1234567);
System.out.println(a == 123); //true System.out.println(b == c); //true System.out.println(a < b); //true
long是基本数据类型,判断是否相等时使用==,即可判断值是否相等。(基本数据类型没有equals()方法)
System.out.println(f == g); //true
Long是引用数据类型,当其数值在[-128,127]之间时,能用==判断是否相等,亦可用 >、< 比较大小。
原因:java.lang.Long.java中:
private static class LongCache {
private LongCache(){}
static final Long cache[] = new Long[-(-128) &