When should null values of Boolean be used?

前端 未结 14 2400
心在旅途
心在旅途 2020-12-04 07:32

Java boolean allows values of true and false while Boolean allows true, false, and null. I have

14条回答
  •  醉酒成梦
    2020-12-04 07:46

    Main purpose for Boolean is null value. Null value says, that property is undefined, for example take database nullable column.

    If you really need to convert everyting from primitive boolean to wrapper Boolean, then you could use following to support old code:

    Boolean set = Boolean.FALSE; //set to default value primitive value (false)
    ...
    if (set) ...
    

提交回复
热议问题