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

Subtyping failure involving capture

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6u65, 7u51, 8
    • Fix Version/s: tbd_major
    • Component/s: tools
    • Labels:

      Description

      The following should compile but does not. Appeared in the paper "Taming Wildcards in Java's Type System," Ross Tate et al., PLDI 2011.

      import java.util.*;

      public class TateFigure5 {

      class C<P extends Number> extends ArrayList<P> {}
      List<? extends List<? extends Number>> cast(List<C<?>> list)
      {return list;}

      }

      The subtyping derivation is straightforward:
      List<C<?>> <: List<? extends List<? extends Number>>
      C<?> <: List<? extends Number>
      List<CAP extends Number> <: List<? extends Number>
      CAP extends Number <: Number
      true

      Interestingly, if C is an interface that extends List rather than a class that extends ArrayList, compilation succeeds.

      This is longstanding behavior, probably due to the way javac handles wildcards in subtyping. Not a regression.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: