Boolean Object and boolean variable issue in JAVA

后端 未结 6 1759
走了就别回头了
走了就别回头了 2020-12-17 08:41

I declare a Boolean variable. For example Boolean dataVal=null;
Now if I execute the following code segment:

if(dataVal)
    System.out.prin         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 09:26

    Because dataVal is being casted to boolean using Boolean.booleanValue() which gets translated to null.booleanValue() which leads you to a NullPointerException.

提交回复
热议问题