-
Bug
-
Resolution: Not an Issue
-
P2
-
8, 8-repo-lambda
There is a bug with most specific and default methods when two signatures are merged from a interface as a result of generic specialization:
class Test {
public void testMergeAbstract(DA<String> da) {
da.m("");
}
public void testMergeInterface(DI<String> di) {
di.m("");
}
abstract class DA<T> {
abstract int m(T arg);
int m(String arg) { return 42; }
}
interface DI<T> {
int m(T arg);
default int m(String arg) { return 42; }
}
}
This gives:
Test.java:234: error: reference to m is ambiguous
di.m("");
^
both method m(T) in DI and method m(String) in DI match
where T is a type-variable:
T extends Object declared in interface DI
1 error
Note that the dual case with abstract classes work just fine.
class Test {
public void testMergeAbstract(DA<String> da) {
da.m("");
}
public void testMergeInterface(DI<String> di) {
di.m("");
}
abstract class DA<T> {
abstract int m(T arg);
int m(String arg) { return 42; }
}
interface DI<T> {
int m(T arg);
default int m(String arg) { return 42; }
}
}
This gives:
Test.java:234: error: reference to m is ambiguous
di.m("");
^
both method m(T) in DI and method m(String) in DI match
where T is a type-variable:
T extends Object declared in interface DI
1 error
Note that the dual case with abstract classes work just fine.
- relates to
-
JDK-7028828 15.12.2.5: Confusion in rules for maximally specific method disambiguation
-
- Closed
-
-
JDK-7028808 Incorrect ambiguity error for methods unified by generics
-
- Closed
-