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

Wildcard capture must use the bounds of the formal

    Details

    • Subcomponent:
    • Resolved In Build:
      b67
    • CPU:
      generic, x86
    • OS:
      linux, solaris_8
    • Verification:
      Verified

      Description

      I believe the process by which we compute a performing a wildcard capture
      conversion should include the formal type parameter's bounds in the result,
      using glb(). The following example shows why. In this case we have an example
      of G1<? extends I2> being a subtype of G1<?>, yet an operation that succeeds on
      the latter will fail on the former.

      ==========$ cat -n T.java
           1 interface I1 {
           2 void i1();
           3 }
           4
           5 class G1<T extends I1> {
           6 T get() { return null; }
           7 }
           8
           9 interface I2 {
          10 void i2();
          11 }
          12
          13 class Main {
          14 void f1(G1<?> g1) {
          15 g1.get().i1();
          16 }
          17 void f2(G1<? extends I2> g1) {
          18 g1.get().i1(); // oops!
          19 g1.get().i2();
          20 }
          21 }
      ==========$ javac T.java
      T.java:18: cannot find symbol
      symbol : method i1()
      location: interface I2
              g1.get().i1(); // oops!
                    ^
      1 error
      ==========$

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ahe Peter Ahe
                Reporter:
                gafter Neal Gafter
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: