the order of execution for the multi-condition – if – Java

如果if有多个条件,且为“与”的关系如,

if(a!=null&&a==b)

如果第一个条件为false,那么第二个条件不会被检测。直接返回false

|| 同理

 

应用在需要首先检测instance是否为空的情况。不会因为条件2的操作而抛出null exception

发表评论

Filed under Uncategorized

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Connecting to %s