What is the difference between Boolean.TRUE and true in Java?

后端 未结 7 1211
情歌与酒
情歌与酒 2020-12-15 03:02

PS: I understand the difference between \"true\" and true.

Edit: I also understand that Boolean.TRUE is a wrapper for the primitive true, my question then is - why d

7条回答
  •  醉话见心
    2020-12-15 03:45

    Boolean.TRUE is a wrapper object and singleton . true is a literal constant. Below are 2 situations where I use wrappers over primitives

    1. I want to store them in Collections
    2. I'd want to have a notion of null. primitive boolean can only represent two states.

提交回复
热议问题