Compiler error : reference to call ambiguous

前端 未结 6 1852
無奈伤痛
無奈伤痛 2020-11-29 09:07

Case 1

static void call(Integer i) {
    System.out.println(\"hi\" + i);
}

static void call(int i) {
    System.out.println(\"hello\" + i);         


        
6条回答
  •  囚心锁ツ
    2020-11-29 09:48

    Looks like it's related to bug #6886431, which seems to be fixed in OpenJDK 7.

    Below is the bug description,

    Bug Description:

    When invoking a method with the following overloaded signatures, I expect an ambiguity error (assuming the arguments are compatible with both):

    int f(Object... args);
    int f(int... args);
    

    javac treats the second as more specific than the first. This behavior is sensible (I prefer it), but is inconsistent with the JLS (15.12.2).

提交回复
热议问题