FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux vladiator 4.8.0-41-generic #44~16.04.1-Ubuntu SMP Fri Mar 3 17:11:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
This code isn't compiled with reference to doSomething is ambiguous error. But if we make the class A non-generic (remove unused <T>), or replace method reference with A<SomeClass>::setString, all will work.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No error since there is no disambiguation
ACTUAL -
Compile error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error:(28, 9) java: reference to doSomething is ambiguous
both method <E>doSomething(Main.SetString<E>) in Main and method <E>doSomething(Main.SetInteger<E>) in Main match.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Main {
private interface SetString<E> {
void setValue(E target, String value);
}
private interface SetInteger<E> {
void setValue(E target, Integer value);
}
private static class A<T> { // if we remove <T>, it will work
public void setString(String string) {}
}
private static <E> void doSomething(SetString<E> a) {}
private static <E> void doSomething(SetInteger<E> a) {}
public static void main(String[] args) {
doSomething(A::setString); // error here. If we make A<SomeClass>, it will work
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
1) private static class A (without <T>)
2) A<SomeObject>::setString instead of A::setString
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux vladiator 4.8.0-41-generic #44~16.04.1-Ubuntu SMP Fri Mar 3 17:11:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
This code isn't compiled with reference to doSomething is ambiguous error. But if we make the class A non-generic (remove unused <T>), or replace method reference with A<SomeClass>::setString, all will work.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No error since there is no disambiguation
ACTUAL -
Compile error
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error:(28, 9) java: reference to doSomething is ambiguous
both method <E>doSomething(Main.SetString<E>) in Main and method <E>doSomething(Main.SetInteger<E>) in Main match.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Main {
private interface SetString<E> {
void setValue(E target, String value);
}
private interface SetInteger<E> {
void setValue(E target, Integer value);
}
private static class A<T> { // if we remove <T>, it will work
public void setString(String string) {}
}
private static <E> void doSomething(SetString<E> a) {}
private static <E> void doSomething(SetInteger<E> a) {}
public static void main(String[] args) {
doSomething(A::setString); // error here. If we make A<SomeClass>, it will work
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
1) private static class A (without <T>)
2) A<SomeObject>::setString instead of A::setString