java.lang.NullPointerException with boolean

后端 未结 4 1973
长情又很酷
长情又很酷 2020-12-01 21:01

I wrote a realy simple code based on another question and here it is:

It throws me an error

java.lang.NullPointerException line 5 and 17

<
4条回答
  •  Happy的楠姐
    2020-12-01 21:48

    So your program must be something like this.

    public class BooleanBug {
    
        public static String bool(Boolean param) {
            if ((null != param) && param.booleanValue() == true) {
                return "a";
            } else if ((null != param) && param.booleanValue() == false) {
                return "b";
            }
            return "c";
    
        }
    
        public static void main(String[] args) {
    
            System.out.println(bool(true));
            System.out.println(bool(null));
            System.out.println(bool(false));
    
        }
    }
    

提交回复
热议问题