Long类型比较大小,long型和Long型区别

时间:2023-03-08 21:17:23
Long类型比较大小,long型和Long型区别

今天写代码发现发现本地程序是正常的,但是发送到测试环境就不正常了,本着对数据的怀疑态度链接了测试数据库,调试程序发现,确实是数据问题,然后数据出现在什么地方呢?才发现是在判断用户所属的teamGroupId和当前用户teamGroupId相等

时出现了问题,于是测试和验证了一下Long

1.基本类型:long,int,byte,float,double,char
2. 对象类型(类): Long,Integer,Byte,Float,Double,Char,String,其它一切java提供的,或者你自己创建的类。

package com.lk.test;

public class TestHundun {
public static void main(String[] args) {
/**
* long 是基本类型
* Long是对象类型,进行比较时:若验证相等则取地址,数值为(-128~127)则相等,
* 因为这段数值取的是相同的地址,其余的则不相等,验证相等可用longValue(),可用equals();
*/
long a = 123456;
long b = 123456; Long c = 123456L;
Long d = 123456L;
Long e = 123457L; System.out.println("(long)a==b:"+(a==b));
System.out.println("(Long)c==d:"+(c==d));
System.out.println("(Long)d<e:"+(d<e));
System.out.println("正确验证c==d:"+(c!=null&&c.equals(d)));
System.out.println("longValue():"+(c.longValue()==d.longValue()));
} }

输出结果:

(long)a==b:true
(Long)c==d:false
(Long)d<e:true
正确验证c==d:true
longValue():true