Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

Java &&(AND)和|| (OR)在IF语句中

我有以下代码:

if(!partialHits.get(req_nr).containsKey(z) || partialHits.get(req_nr).get(z) < tmpmap.get(z)){  
    partialHits.get(z).put(z, tmpmap.get(z));  
} 

partialHitsHashMap 在哪里。
如果第一个陈述为真会怎样? Java还会检查第二条语句吗?因为为了使第一条语句为真,所以HashMap不应包含给定的键,因此如果选中了第二条语句,则将获得NullPointerException
简单来说,如果我们有以下代码

if(a && b)  
if(a || b) 

Java将在第一种情况下检查b是否a为false,a在第二种情况下是否为true?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

&& 如果a为false就不会去检查b
|| 如果a为true就不会去检查b


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...