作者TonyQ (骨头)
看板java
标题Re: [问题] && 和 &
时间Fri Aug 18 20:39:45 2006
※ 引述《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