This issue may be similar to Reference is ambiguous with generics, but I guess it is a little different.
In this case
public class MyTest {
public static void main(String[] args) {
MyTest test = new MyTest();
test.add(test::method);
}
public void add(Interface1 i1) {
}
public <T extends Interface2> void add(T i2) {
}
private void method() {
}
public interface Interface1 {
void method1();
}
public interface Interface2 {
boolean isMethod2();
void setMethod2(boolean required);
}
}
, it is compiled with Eclipse Neon.2, but not with javac 1.8.0_121 or 1.8.0_152, giving an error:
MyTest.java:5: error: reference to add is ambiguous
test.add(test::method); ^both method add(Interface1) in MyTest and method add(T) in MyTest match
where T is a type-variable:
T extends Interface2 declared in method add(T)
However, if
public <T extends Interface2> void add(T i2) {
is changed to:
public void add(Interface2 i2) {
then it id compiled by javac.
So, is it correct for javac to say T is a type-variable, and is not sub-type of Interface2, so it complains about ambiguity, and if so, then Eclipse is wrong?