I might blind some people here but I will fire anyway.
I know I can do:
Class<Response> c = Response.class;
To get the class of the object. Assuming that the Response object is Response<T>
I want to do something like the following
Class<Class<User>> c = Response<User>.class;
My full problem:
public class RequestHelper<T> extends AsyncTask<String, Response, T> {
@Override
protected T doInBackground(String... strings) {
...
Response <T> r = objectMapper.readValue( result, Response.class );
return r .getResponse();
}
}
//and
public class Response <R> {
private R response;
public R getResponse() {
return response;
}
}
But above the parameter has not been specified in the assignment. In theory the correct way would require:
public class RequestHelper<T> extends AsyncTask<String, Response, T> {
@Override
protected T doInBackground(String... strings) {
...
Response <T> r = objectMapper.readValue( result, Response <T>.class );
return r.getResponse();
}
}
But that generates a "Cannot select from parameterized type" lint error.
Alternatively I could pass the class in the constructor:
public class RequestHelper<T> extends AsyncTask<String, Response, T> {
....
public RequestHelper(Class<Class<T>> tClass){
this.tClass = tclass;
}
@Override
protected T doInBackground(String... strings) {
...
Response <T> r = objectMapper.readValue( result, tclass );
return r.getResponse();
}
}
// where the init of the class would have been:
new RequestHelper<User>( Response<User>.class );