小编Kri*_*esh的帖子

调用重载方法时,错误消息"对于类型Other是不明确的"

我知道以下程序会出现编译错误:

方法runThis(Integer)对于Other类型是不明确的

我不明白的是原因.

public class Other {


    public static void main(String[] args) {

        runThis(null);

    }

    private static void runThis(Integer integer){
        System.out.println("Integer");
    }

    private static void runThis(Object object){
        System.out.println("Object");
    }

    private static void runThis(ArithmeticException ae){
        System.out.println("ArithmeticException");
    }

}
Run Code Online (Sandbox Code Playgroud)

此外,当我按如下方式更改程序时,它会输出"ArithmeticException".我也不知道原因.任何人都可以向我解释这个吗?

public class Other {


public static void main(String[] args) {

    runThis(null);

}

private static void runThis(Exception exception){
    System.out.println("Exception");
}

private static void runThis(Object object){
    System.out.println("Object");
}

private static void runThis(ArithmeticException ae){
    System.out.println("ArithmeticException");
}
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
2
解决办法
772
查看次数

标签 统计

java ×1