primitive type bounds

Anna Kozlova anna.kozlova at jetbrains.com
Sat Nov 16 12:13:33 PST 2013


Hi,

 

I don't understand why there is a compilation error (b. 115) here:

 

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

}

 

java: incompatible types: inference variable U has incompatible bounds

    equality constraints: java.lang.Integer

    lower bounds: java.lang.Integer,int

 

How does javac get 'int' lower bound here? 

 

Thanks,

Anna



More information about the lambda-dev mailing list