java.lang.Boolean为null时

 

public class TestBooleanNull {

    public static void main(String[] args) {
        if (test()) {
            System.out.println("1232");
        }
    }

    /**
     * java.lang.Boolean是对象,可以为null。但null作为if的条件会报npe
     * @return
     */
    private static Boolean test() {
        return null;
    }

}

 

posted @ 2016-10-14 14:09  沧海一滴  阅读(13840)  评论(0)    收藏  举报