Note: this question has been marked as a duplicate of Ambiguous varargs methods but it is not a duplicate. That question deals with confusion between Integer
/int
(here, it would be Double
/double
). But my question deals with ambiguity between double
/lack of double
, and puzzles about the lack of ambiguity when using Double
instead.
Why does Java disambiguate based on Double
but not double
in the cases below?
public class Ambiguity {
void foo(double d, Object... o) {}
void foo(Object... o) {}
void bar() {
foo(1.0d, "Hi"); // complains about ambiguity
}
void foo2(Double d, Object... o) {}
void foo2(Object... o) {}
void bar2() {
foo2(1.0d, "Hi"); // fine
}
}