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

Problem with underconstrained type variables

XMLWordPrintable

    • generic
    • generic

      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;
          }

      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: