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

Problem with underconstrained type variables

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      This program does not compile:

      import java.util.LinkedHashSet;
      import java.util.Set;

      public class GenericsTest {

          public class A {};

          public class B extends A {};

          public static void main(String[] args) {
              GenericsTest g = new GenericsTest();
              Set<A> set = g.newSet(g.new B());
          }

          public <T, V extends T> Set<T> newSet(V... objects) {
              Set<T> set = new LinkedHashSet<T>();
              for (T t : objects) {
                  set.add(t);
              }
              return set;
          }

      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mcimadamore Maurizio Cimadamore
              Reporter:
              ahe Peter Ahe
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: