Details
-
Bug
-
Resolution: Fixed
-
P4
-
5.0, 7, 8
Description
JLS 15.12.2.5 fails to specify the behavior of the following test case:
class Foo<T> {
void m(Integer arg) {}
void m(T arg) {}
}
void m1(Foo<Integer> f1, Integer i) {
f1.m(i);
}
Class type Foo<Integer> has two methods with the same signature. Of course, neither is more specific than the other. Clearly, there should be an ambiguity error. The behavior in such cases is outlined as follows:
1) If all the maximally specific methods have override-equivalent signatures, then:
a) If exactly one of the maximally specific methods is not declared 'abstract', ...
b) Otherwise, if all the maximally specific methods are declared 'abstract', and the signatures of all of the maximally specific methods have the same erasure, ...
2) Otherwise, we say the method invocation is ambiguous, and a compile-time error occurs.
There is no case 1c, for when neither 1a nor 1b are true.
As an aside, I think "the signatures of all of the maximally specific methods have the same erasure" is redundant, per 1. That is
"all the maximally specific methods have override-equivalent signatures"
implies
"the signatures of all of the maximally specific methods have the same erasure"
class Foo<T> {
void m(Integer arg) {}
void m(T arg) {}
}
void m1(Foo<Integer> f1, Integer i) {
f1.m(i);
}
Class type Foo<Integer> has two methods with the same signature. Of course, neither is more specific than the other. Clearly, there should be an ambiguity error. The behavior in such cases is outlined as follows:
1) If all the maximally specific methods have override-equivalent signatures, then:
a) If exactly one of the maximally specific methods is not declared 'abstract', ...
b) Otherwise, if all the maximally specific methods are declared 'abstract', and the signatures of all of the maximally specific methods have the same erasure, ...
2) Otherwise, we say the method invocation is ambiguous, and a compile-time error occurs.
There is no case 1c, for when neither 1a nor 1b are true.
As an aside, I think "the signatures of all of the maximally specific methods have the same erasure" is redundant, per 1. That is
"all the maximally specific methods have override-equivalent signatures"
implies
"the signatures of all of the maximally specific methods have the same erasure"
Attachments
Issue Links
- duplicates
-
JDK-8148464 15.12.2.5: Unclear interpretation of a method's "erasure"
-
- Closed
-
- relates to
-
JDK-8024484 8.4.2: Define when bounds are the same
-
- Open
-
-
JDK-7028808 Incorrect ambiguity error for methods unified by generics
-
- Resolved
-
-
JDK-7034913 15.12.2.5: Resolution of call to abstract methods is nondeterministic
-
- Closed
-
-
JDK-8013224 Most specific: spurious ambiguity error between abstract and default method
-
- Resolved
-
-
JDK-8148464 15.12.2.5: Unclear interpretation of a method's "erasure"
-
- Closed
-
(1 relates to)