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

Inference failure with nested invocation

XMLWordPrintable

    • b32
    • Verified

        The following fails to compile:

        ---

        public class FirstNonNull {

        public static class C<T> {}

        public static <T> T firstNonNull(T first, T second) {
            return first != null ? first : second;
        }

        public static C<String> doesNotCompile = firstNonNull(new C<String>(), new C<>());

        }

        ---

        Error:

        public static C<String> doesNotCompile = firstNonNull(new C<String>(), new C<>());
                                                             ^
            inferred: C<? extends Object>
            upper bound(s): C<String>,Object

        ---

        This is a regression -- it compiles correctly with the initial release of JDK 8.

        Reported on Stack Overflow: http://stackoverflow.com/questions/25490581

              mcimadamore Maurizio Cimadamore
              dlsmith Dan Smith
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: