在发布此问题之前,我已经参考了这个问题.
检查Null Wrappers是否符合原始值
我有我要检查情况Wrapper Integer与null以及0
if( statusId != null || statusId != 0 ) //statusId is Integer it maybe 0 or null
// Do Somethimg here
Run Code Online (Sandbox Code Playgroud)
我怎样才能克服这种情况?
替换or为and:
if( statusId != null && statusId != 0 )
Run Code Online (Sandbox Code Playgroud)
它会起作用,因为只有statusId不是null :
statusId != null
Run Code Online (Sandbox Code Playgroud)
你会尝试拆箱statusId到int:
statusId != 0
Run Code Online (Sandbox Code Playgroud)
而在的情况statusId就是null,短路&&运营商将防止抛出NullPointerException 的statusId != 0将不予评审.
| 归档时间: |
|
| 查看次数: |
6213 次 |
| 最近记录: |