I need to pass a generic type class to the class constructor. The SpiceRequest class from RoboSpice Android for reference to the constructor.
It seems strange that a class requires passing the generic class to the counter-constructor when it can be accessed from the most general type, in this case RESULT.class , but maybe I'm wrong about that. In any case, I do not want to change the library code, but rather I should use the generic type for the generic type SpiceRequest , Map<String, ? extends Object> Map<String, ? extends Object> . Here is 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 tried Map.class with a compiler error: The constructor SpiceRequest<Map<String,? extends Object>>(Class<Map>) is undefined. The constructor SpiceRequest<Map<String,? extends Object>>(Class<Map>) is undefined.
Map<String, ? extends Object>.class Map<String, ? extends Object>.class gives an error: Syntax error on tokens, PrimitiveType expected instead , specifically emphasizing ? extends Object ? extends Object . It also gives the same error as Map.class .
And Map.<String, ? extends Object>class Map.<String, ? extends Object>class also gives the same compiler error.
What is the correct way to get the generic class Class<Map<String, ? extends Object>> Class<Map<String, ? extends Object>> ?
Jeff lockhart
source share