Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268148

unchecked warnings handle ? and ? extends Object differently

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8, 11, 17
    • Fix Version/s: 18
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b14

      Description

      Per 4.5.1, the wildcard ? extends Object is equivalent to the unbounded wildcard ?.

      In the following example javac emits a different unchecked in one example but not the other, and the only difference is the use of ? vs. ? extends Object.

      ```
      import java.util.List;

      class T {
        void f(List<? extends Object> x) {}

        void g(List<?> x) {}

        void h(List<String> x) {
          f((List) x);
          g((List) x);
        }
      }
      ```

      $ javac -fullversion -Xlint:all T.java
      javac full version "17-ea+24-2164"
      T.java:9: warning: [unchecked] unchecked method invocation: method f in class T is applied to given types
          f((List) x);
           ^
        required: List<? extends Object>
        found: List
      T.java:9: warning: [unchecked] unchecked conversion
          f((List) x);
            ^
        required: List<? extends Object>
        found: List
      2 warnings

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: