关于Java Integer和Long直接比较


Integer和Long不能直接equals比较会返回False

Long.class源码

`

public boolean equals(Object obj) {
    if (obj instanceof Long) {
        return this.value == (Long)obj;
    } else {
        return false;
    }
}

`

Integer.class源码

`

public boolean equals(Object obj) {
    if (obj instanceof Integer) {
        return this.value == (Integer)obj;
    } else {
        return false;
    }
}

`

解决方法

Long变量.equals(Integer变量.longValue()) 返回True


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM