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

Trouble compiling code that uses diamond instantiation.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 9, 10, 11, 12, 13, 14, 15, 16
    • tools
    • None
    • 9
    • generic
    • generic

      Report from compiler-dev:

      The following code does not compile:

      import java.util.List;
      import java.util.function.Predicate;

      public class X<T> {
          public X(List<? extends T> l) {
          }
          void m(List<? extends String> list){
              X<String> boo3 = new X<>(findAll(list, s -> s.length() > 0)){};
          }

          static <T> List<T> findAll(List<? extends T> collection,
                                     Predicate<? super T> condition) {
              return null;
          }
      }

      Problem goes back all the way to JDK9.

      Error reported:

      error: cannot find symbol
        symbol: class <captured wildcard>
        location: class X<T>
        where T is a type-variable:
          T extends Object declared in class X



            vromero Vicente Arturo Romero Zaldivar
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: