Re: [問題] && 和 &
※ 引述《seekyou (galagala~N )》之銘言:
: public class ShortCircuit {
: public static void main(String[] args) {
: String s=null;
: if((s != null) && s.length() > 20)
&& 是 前面的條件檢查
如果不符之後
就不會去檢查s.length()
& 則反之 , 它會去檢查t.length()
因為t是null
null 當然不能用.length()
就會出現nullPointerException
: System.out.println(s);
: String t=null;
: if((t != null) & t.length() > 20)
: System.out.println(t);
: }
: }
: 如題,第一個if不會印出東西,(短路運算子)
: 第二個if為什麼會有NullPointerException呢?
: 謝謝回應
--
String temp="relax"; | Life just like programing
while(buringlife) String.forgot(temp); | to be right or wrong
while(sleeping) brain.setMemoryOut(); | need not to say
stack.push(life.running); | the complier will
stack.push(scouting.buck()); | answer your life
stack.push(bowling.pratice()); | Bone everything
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.138.240.58
討論串 (同標題文章)
java 近期熱門文章
PTT數位生活區 即時熱門文章