这是将已定义的int设置为null的最佳方法?
private int xy(){
int x = 5;
x = null; //-this is ERROR
return x;
}
Run Code Online (Sandbox Code Playgroud)
所以我选择这个
private int xy(){
Integer x = 5;
x = null; //-this is OK
return (int)x;
}
Run Code Online (Sandbox Code Playgroud)
然后我需要这样的东西:
if(xy() == null){
// do something
}
Run Code Online (Sandbox Code Playgroud)
我的第二个问题是否可以安全地将Integer转换为int?
谢谢你的回复.