瞎子不pei學編程

   // 黃色警告
    private Boolean on; 
    public boolean isOn() {
     //on爲boolean  報錯Operator '==' cannot be applied to 'boolean', 'null'
        if(on==null ||on==false)  //1. on==false Simplify
            return false;
        return on;   // 2. Simplify 'on' to true
    }

    public boolean isOn() {
        if(on==null || !on) {      //'if' statement can be simplified 
            return false;
        }
        return true;
    }

    public boolean isOn() {
        return on != null && on;
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章