Javac Bug?

Anna Kozlova anna.kozlova at jetbrains.com
Fri Apr 25 11:33:15 UTC 2014


Hi,

This code compiles

class Test {
   {
        putPrefWriter(Short.class, Preferences::putInt);
    }

    private static <T> void putPrefWriter(Class<T> type, PrefWriter<T>
prefWriter) {}

    interface PrefWriter<T> {
        void write(Preferences preferences, String key, T value);
    }
}

but this is not (only parameters order was changed)

class Test {
    {
        putPrefWriter(Preferences::putInt, Short.class);
    }

    private static <T> void putPrefWriter(PrefWriter<T> prefWriter, Class<T>
type) {}

    interface PrefWriter<T> {
        void write(Preferences preferences, String key, T value);
    }
}

As for me, javac should reject both cases due to
http://docs.oracle.com/javase/specs/jls/se8/html/jls-18.html#jls-18.2.2 (if
T is a primitive type, let T' be the result of applying boxing conversion
(§5.1.7) to T. Then the constraint reduces to ‹S = T'›.)

Initially reported as http://youtrack.jetbrains.com/issue/IDEA-124366

Thanks,
Anna



More information about the lambda-dev mailing list