-
Sub-task
-
Resolution: Delivered
-
P4
-
21
Prior to JDK 21, the `javac` compiler was omitting some "potentially ambiguous overload" warnings enabled by the `-Xlint:overloads` option.
If the `-Xlint:overloads` option is enabled, the compiler warns when the methods in a class create a potential ambiguity for method invocations containing an implicit lambda expression parameter like `x -> { ... }`. An ambiguity can occur if two or more methods could match such a method call, like when one method takes a `Consumer<Integer>` parameter where the other takes an `IntConsumer`. For example, the `javac` compiler should issue a warning for code such as:
```
interface I {
void foo(Consumer<Integer> c);
void foo(IntConsumer c);
}
```
Prior to JDK 21, the warning was only issued for a class if one of the methods was declared in the class. The `javac` compiler now also warns when neither method is declared in the class. That is, both methods are inherited from supertypes. For example, for code like:
```
interface I {
void foo(Consumer<Integer> c);
}
interface J {
void foo(IntConsumer c);
}
interface K extends I, J {}
```
If the `-Xlint:overloads` option is enabled, the compiler warns when the methods in a class create a potential ambiguity for method invocations containing an implicit lambda expression parameter like `x -> { ... }`. An ambiguity can occur if two or more methods could match such a method call, like when one method takes a `Consumer<Integer>` parameter where the other takes an `IntConsumer`. For example, the `javac` compiler should issue a warning for code such as:
```
interface I {
void foo(Consumer<Integer> c);
void foo(IntConsumer c);
}
```
Prior to JDK 21, the warning was only issued for a class if one of the methods was declared in the class. The `javac` compiler now also warns when neither method is declared in the class. That is, both methods are inherited from supertypes. For example, for code like:
```
interface I {
void foo(Consumer<Integer> c);
}
interface J {
void foo(IntConsumer c);
}
interface K extends I, J {}
```