if(
this.con==null||this.con.isClosed()){
return this.con = DBUtil.getConnection();
}
這個(gè)判斷實(shí)現(xiàn)判斷con是否為空然后在判斷isClosed,如果為空,就直接返回。不會(huì)載執(zhí)行isClosed的判斷。這就是短路。
這就相當(dāng)于
if(this.con==null){
return this.con = DBUtil.getConnection();
}
if(this.con.isClosed()){
return this.con = DBUtil.getConnection();
}
并且上面的代碼也不會(huì)發(fā)生NullPointerException 的異常。因?yàn)槿绻麨榭眨椭苯尤〉眯碌倪B接。
|----------------------------------------------------------------------------------------|
版權(quán)聲明 版權(quán)所有 @zhyiwww
引用請注明來源 http://m.tkk7.com/zhyiwww
|----------------------------------------------------------------------------------------|
posted on 2010-02-09 11:45
zhyiwww 閱讀(704)
評論(0) 編輯 收藏 所屬分類:
j2ee