Get the Integer type data of the interface as null, report int java.lang.Integer.intValue()' on a null object reference

The null value returned by the receiving interface is also to be processed. If the return type is an Integer type, you return null with the same properties as declaring a variable initialization value to null. The return value is null and there is no error. The key is to judge after returning if !=null and then operate
//
Integer and int have an autoboxing feature, I guess it is because you return null. When using your return value, the compiler will automatically convert it to int. As a result, a null pointer exception was reported. You can look at the source code of Integer. There should be a method involving autoboxing conversion.

Interger v;
//这样去判断值会保存
 if(v == 1){
    
    
...
    }else if(v == 0){
    
    
        ...
    }else if(v == null){
    
    
        ...
    }    

//To judge if !=null and then operate, so that it will not report, it is necessary to deal with not equal to null

if(v!=null){
    
    

	 if(v == 1){
    
    
	...
	    }else if(v == 0){
    
    
	        ...
	    }else if(v == null){
    
    
	        ...
	    } 
}else{
    
    

.....
}

Guess you like

Origin blog.csdn.net/ShiXinXin_Harbour/article/details/109647204