JDK-8268148 : unchecked warnings handle ? and ? extends Object differently
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,11,17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-06-02
  • Updated: 2021-09-03
  • Resolved: 2021-09-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18
18 masterFixed
Related Reports
Relates :  
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
Comments
Changeset: ff4018bc Author: Vicente Romero <vromero@openjdk.org> Date: 2021-09-03 15:20:23 +0000 URL: https://git.openjdk.java.net/jdk/commit/ff4018bc867841b566d619029fb637a128bc39a7
03-09-2021

Yes, per 4.5.1 and JDK-6480391, '? extends Object' is an "unbounded wildcard", so 5.1.9 says no unchecked warning should occur.
12-07-2021