-
Bug
-
Resolution: Unresolved
-
P5
-
8, 8u40, 8u60, 9
The following class (provided by Stephan Herrmann) fails to compile, as expected, but produces two error messages. The second is unnecessary and confusing. It also depends on the order of the 'execute1' declarations -- apparently the first declaration is arbitrarily chosen if an ambiguity occurs, so reordering eliminates the second error message.
Source:
class HermannCompatibility {
// generic method
interface ConsumerA {
<T> void accept(int i);
}
// non-generic
interface ConsumerB {
void accept(int i);
}
void execute1(ConsumerA c) {}
void execute1(ConsumerB c) {}
void test() {
execute1(x -> {});
}
}
Output:
HermannCompatibility.java:17: error: reference to execute1 is ambiguous
execute1(x -> {}); // compiles in Eclipse, not with javac
^
both method execute1(ConsumerA) in HermannCompatibility and method execute1(ConsumerB) in HermannCompatibility match
HermannCompatibility.java:17: error: incompatible types: invalid functional descriptor for lambda expression
execute1(x -> {}); // compiles in Eclipse, not with javac
^
method <T>(int)void in interface ConsumerA is generic
where T is a type-variable:
T extends Object declared in method <T>accept(int)
Source:
class HermannCompatibility {
// generic method
interface ConsumerA {
<T> void accept(int i);
}
// non-generic
interface ConsumerB {
void accept(int i);
}
void execute1(ConsumerA c) {}
void execute1(ConsumerB c) {}
void test() {
execute1(x -> {});
}
}
Output:
HermannCompatibility.java:17: error: reference to execute1 is ambiguous
execute1(x -> {}); // compiles in Eclipse, not with javac
^
both method execute1(ConsumerA) in HermannCompatibility and method execute1(ConsumerB) in HermannCompatibility match
HermannCompatibility.java:17: error: incompatible types: invalid functional descriptor for lambda expression
execute1(x -> {}); // compiles in Eclipse, not with javac
^
method <T>(int)void in interface ConsumerA is generic
where T is a type-variable:
T extends Object declared in method <T>accept(int)