Boolean.TRUE == myBoolean与Boolean.TRUE.equals(myBoolean) [英] Boolean.TRUE == myBoolean vs. Boolean.TRUE.equals(myBoolean)

查看:1399
本文介绍了Boolean.TRUE == myBoolean与Boolean.TRUE.equals(myBoolean)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有过的情况下使用等于(布尔) == 将与交易时返回不同的结果布尔对象?

Is there ever a situation where using equals(Boolean) and == would return different results when dealing with Boolean objects?

Boolean.TRUE == myBoolean;

Boolean.TRUE.equals(myBoolean);

我没有想过基本类型在这里,只是布尔对象。

I'm not thinking about primitive types here, just Boolean objects.

推荐答案

如何

System.out.println(new Boolean(true) == new Boolean(true));
System.out.println(new Boolean(true) == Boolean.TRUE);

(既打印假,为同样的理由的任何其他类型的对象)。

这篇关于Boolean.TRUE == myBoolean与Boolean.TRUE.equals(myBoolean)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆