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

javac, for method references a primitive type can be added as a bound

XMLWordPrintable

    • b15

        For this code:

        class Test {
            static <U> Iterable<U> map(Mapper<String, U> mapper) {
                return null;
            }

            static void test() {
                Iterable<Integer> map = map(Test::length);
            }

            public static <T> int length(String s) {
                return 0;
            }
        }

        interface Mapper<T, U> {
            U map(T t);
        }

        javac generates this error message:

        Test.java:7: error: incompatible types: inference variable U has incompatible bounds
                Iterable<Integer> map = map(Test::length);
                                           ^
            equality constraints: Integer
            lower bounds: Integer,int <--- primitive type in bound
          where U is a type-variable:
            U extends Object declared in method <U>map(Mapper<String,U>)
        1 error

        reported by anna.kozlova_at_jetbrains.com in compiler-dev

              vromero Vicente Arturo Romero Zaldivar
              vromero Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: