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

javac, inference don't seem to deal with target types in a consistent way

    Details

      Description

      Having this code:

      import java.util.Collection;
      import java.util.List;

      abstract class TypeTest {

          interface I {}

          public Collection<? extends I> excludeFrom(Collection<? extends I> include, Collection<? extends I> exclude) {
              return copyOf(filter(include, not(in(exclude))));
          }

          interface Predicate<T> {
              boolean apply(T t);
          }

          abstract <T> Predicate<T> in(Collection<? extends T> target);
          abstract <T> Predicate<T> not(Predicate<T> aPredicate);
          abstract <E> List<E> copyOf(Iterable<? extends E> elements);

          abstract <T> Iterable<T> filter(Iterable<T> unfiltered, Predicate<? super T> predicate);
      }

      javac 8 produces a compiler error. But if excludeFrom is replaced with:

          public Collection<? extends I> filter(Collection<? extends I> include, Collection<? extends I> exclude) {
              Iterable<? extends I> myFiltered = filter(include, not(in(exclude)));
              return copyOf(myFiltered);
          }

      it works.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                vromero Vicente Arturo Romero Zaldivar
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: