I need to pass the class of a generic type into a class's constructor. The class is SpiceRequest from the RoboSpice Android library for a reference to the constructor.
It seems odd that the class requires passing the generic's class into the contstructor, when it could be accessed from the generic type itself, in this case RESULT.class
, but maybe I'm wrong about this. Anyway, I'm not looking to change the library's code, but rather need to use a generic type for the generic type of SpiceRequest
, Map<String, ? extends Object>
. Here's my code:
SpiceRequest<Map<String, ? extends Object>> request =
new SpiceRequest<Map<String, ? extends Object>>(???) {
...
};
And the signature of the SpiceRequest
constructor:
public SpiceRequest(final Class<RESULT> clazz) {
...
}
For ??? I have tried Map.class
with the compiler error: The constructor SpiceRequest<Map<String,? extends Object>>(Class<Map>) is undefined.
Map<String, ? extends Object>.class
gives the error: Syntax error on tokens, PrimitiveType expected instead
, specifically underlining ? extends Object
. It also gives the same error as Map.class
.
And Map.<String, ? extends Object>class
gives the same compiler error as well.
What is the correct way to get the generic class Class<Map<String, ? extends Object>>
?