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

4.9: Clarify membership of intersection types for wildcard parameterizations



      From JLS 3 4.9: " the intersection type has the same members as a class type (Chapter 8, Classes) with an empty body, direct superclass Ck and direct superinterfaces T1', ..., Tn'"

      This does not consider the possibility that one of Ck or Ti' may be a wildcard-paramterized type.

      <T extends Iterable<?>> void m1() {}
      <T extends Iterable<?> & Comparable<?>> void m2() {}

      In this case, the members of the supertypes (and, therefore, the members of the intersection) are undefined (4.5.2).

      It seems like the right thing to do is to make Ti' = capture(Ti), and similar for Ck. But some caution is warranted, since capture variables do not otherwise appear in class declarations.

      It would also be possible to express the implicit class generically:

      Given type C<?> & D<? extends Foo, ? super Bar>

      We have class:

      class Intersect<S extends Bounds1, T extends Bounds2, U extends Bounds3> implements C<S>, D<T, U> {}

      And the members of the intersection are the members of class Intersect<?, ? extends Foo, ? super Bar>

      That's a lot of work to specify, though . . . If nothing else, the fact that it could be done demonstrates that the capture alternative, which works out to the same thing, is fundamentally sound.


          Issue Links



              • Assignee:
                dlsmith Dan Smith
                dlsmith Dan Smith
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: