I don't know IntelliJ's workings, but I can tell you the reason why it doesn't compile.
The method defined in the class Enum<T extends Enum<T>>
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
has a first argument that is the class of a type T
which is defined by T extends Enum<T>
. That is, it extends an enumeration type with the same generic type as itself.
When you call the method with the first argument as
Class<? extends Enum<?>>
you are not specifying that the two ?
are in fact the same type, as required. This throws the mismatch error.
What you can do with your method is turn it generic:
public static <E extends Enum<?>> void hello(Class<E> q)
but as you can imagine, this will still not compile because ?
is not necessarily E
. So you need to spell it out:
public static <E extends Enum<E>> void hello(Class<E> q)
and this will compile.
Edit: another way to think about it
You could think of fixing your method signature
public void hello(Class<? extends Enum<?>> q)
by changing it to
public void hello(Class<E extends Enum<E>> q)
just to specify that the two wildcards are the same. The concept is right, but the syntax is not legal. You must define what E
is (either by making your method generic or your class).