class Test {
static void foo(Class<?> clazz) {
baz(clazz);
// bar(clazz, clazz); <------- THIS LINE ERRORS OUT
}
static <T> void bar(Class<T> type, Class<? extends T> subtype) {}
static <T> void baz(Class<T> clazz) {
bar(clazz, clazz);
}
}
The post title might be too vague so edits are welcome. But basically in the code snippets above, calling bar
directly from foo
is not allowed. However, wrapping that call in baz
(that does nothing more than calling bar
) works.
Why is this counter-intuitive behavior? Is this a design flaw of the Java type system or a well grounded decision?