避免!=空语句 - Avoiding != null statements

问题:

I use object != null a lot to avoid NullPointerException . 我常用object != null来避免NullPointerException html

Is there a good alternative to this? 有没有好的替代方法? java

For example: 例如: api

if (someobject != null) {
    someobject.doCalc();
}

This avoids a NullPointerException , when it is unknown if the object is null or not. 若是不知道对象是否为null ,则能够避免NullPointerException oracle

Note that the accepted answer may be out of date, see https://stackoverflow.com/a/2386013/12943 for a more recent approach. 请注意,接受的答案可能已过时,请参阅https://stackoverflow.com/a/2386013/12943以获取最新的方法。 app


解决方案:

参考一: https://stackoom.com/question/18dS/避免-空语句
参考二: https://oldbug.net/q/18dS/Avoiding-null-statements
相关文章
相关标签/搜索