Inference question

Boaz Nahum boaznahum at gmail.com
Tue Feb 5 04:28:55 PST 2013


Hi.

Can you please confirm if the compilation error  below is compiler bug or
known limitation (works in JDK 7 ):

public class TypeInterfrer3 {


    private interface TKey<T> {

    }

    public static <TK extends TKey<?>> TK createKey(TK relativeKey) {
        return null;
    }


    static <T> T getValue(TKey<T> key) {
        return null;
    }


    public static void main(String[] args) {


        TKey<Integer> ki = new TKey<Integer>() {}



        // *OK*
        int i = getValue(createKey(ki));

        // *OK*
        double d0 = getValue(ki);


        // *OK*
        double d1 = getValue(TypeInterfrer3.<TKey<Integer>>createKey(ki));

        // *OK*
        double d2 = (int)getValue(createKey(ki));

       * // Fails:
        // java: incompatible types: inference variable T has incompatible
bounds
        //   equality constraints:java.lang.Integer
        ///   upper bounds:java.lang.Double, java.lang.Object*
        double d3 = getValue(createKey(ki));


    }


}

Thanks
Boaz


More information about the lambda-dev mailing list