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

unchecked warnings handle ? and ? extends Object differently

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 18
    • 8, 11, 17
    • tools
    • None
    • b14

      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

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

              Created:
              Updated:
              Resolved: