Why do two methods with signature (primitive, wrapper) and (primitive, primitive) cause the method call (wrapper, primitive) to be ambiguous?

前端 未结 3 1813
南旧
南旧 2020-12-17 11:12

It\'s just an exercise but I can\'t figure out the ambiguity:

private static void flipFlop(String str, int i, Integer iRef) {
System.out.println(str + \"ciao         


        
3条回答
  •  盖世英雄少女心
    2020-12-17 11:16

    If you enjoy riveting reading, here is the relevant portion of the Java Language specification that describes how methods are resolved.

    But basically your third argument can be interpreted as a primitive or an autoboxed wrapper, and the compiler can't figure out what you want. Both methods are "maximally specific" to use the JLS terminology.

提交回复
热议问题