Boolean.TRUE == myBoolean vs. Boolean.TRUE.equals(myBoolean)

后端 未结 4 1325
执笔经年
执笔经年 2021-02-08 08:51

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

<         


        
4条回答
  •  孤独总比滥情好
    2021-02-08 09:31

    How about:

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

    (both print false, for the same reason as any other type of objects).

提交回复
热议问题