If you really want to get the static type as you require, you can force your way to it using casts (albeit through raw types):
Class<Map<String, Object>> cl = (Class) Map.class;
However, as pointed in other comments and other answer, that doesn't help you as, at runtime, your class.getConstructor()
call will only see Map.class
anyway.
Just consider the signature of getConstructor
:
getConstructor(Class<?>... parameterTypes)
The implementation retrieves the constructor by comparing parameters (check the source of java.lang.Class.arrayContentsEq(Object[], Object[])
).
To summarize, it boils down to comparing (Class) cl == Map.class
, and that returns true
at runtime, which explains why it's no use looking for the generic class instance.
The value of Class<Map<String, Object>> cl
would only be effectual if that were used for static type checking, but in this case, it doesn't help.