相关疑难解决方法(0)

多个重载方法:null是否等于NullPointerException?

public class TestMain {

    public static void methodTest(Exception e) {
        System.out.println("Exception method called");
    }

    public static void methodTest(Object e) {
        System.out.println("Object method called");
    }

    public static void methodTest(NullPointerException e) {
        System.out.println("NullPointerException method called");
    }

    public static void main(String args[]) {
        methodTest(null);
    }   
}
Run Code Online (Sandbox Code Playgroud)

输出:调用NullPointerException方法

java null overloading reference nullpointerexception

25
推荐指数
2
解决办法
1329
查看次数