Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8026369 javac potentially ambiguous overload warning needs an improved scheme
  3. JDK-8303274

Release Note: Generate "potentially ambiguous overload" Warning for Inherited Methods

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 21
    • 21
    • tools

      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 {}
      ```

            vromero Vicente Arturo Romero Zaldivar
            acobbs Archie Cobbs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: