FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [verzi��sz��m: 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The attached class C doesn't compile with javac but compiles with Eclipse Mars
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the given class.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation successful
ACTUAL -
Fails with ambiguity error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
error: reference to f is ambiguous
f(p1, ArrayList::new);
^
both method f(Consumer<Object>,Function<Object,Object>) in C and method f(Consumer<Object>,Supplier<Object>) in C match
C.java:1909: error: incompatible types: invalid constructor reference
f(p1, ArrayList::new);
^
no suitable constructor found for ArrayList(Object)
constructor ArrayList.ArrayList(int) is not applicable
(cannot infer type-variable(s) E
(argument mismatch; Object cannot be converted to int))
constructor ArrayList.ArrayList() is not applicable
(cannot infer type-variable(s) E
(actual and formal argument lists differ in length))
constructor ArrayList.ArrayList(Collection) is not applicable
(cannot infer type-variable(s) E
(argument mismatch; Object cannot be converted to Collection<? extends E>))
constructor ArrayList.ArrayList(int) is not applicable
(cannot infer type-variable(s) E
(argument mismatch; Object cannot be converted to int))
constructor ArrayList.ArrayList() is not applicable
(cannot infer type-variable(s) E
(actual and formal argument lists differ in length))
constructor ArrayList.ArrayList(Collection) is not applicable
(cannot infer type-variable(s) E
(argument mismatch; Object cannot be converted to Collection<? extends E>))
where E is a type-variable:
E extends Object declared in class ArrayList
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
class C {
void f(Consumer<Object> p1, Function<Object, Object> p2) {
}
void f(Consumer<Object> p1) {
f(p1, ArrayList::new);
}
void f(Consumer<Object> p1, int p2) {
f(p1, () -> new ArrayList<>(p2));
}
void f(Consumer<Object> f1, Supplier<Object> f2) {
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Cast ArrayList::new to supplier manually.