避免!=空語句 - 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
相關文章
相關標籤/搜索