Define a list <T> when T is defined as a variable "Class t"
I am trying to write a SyncAdapter that creates a set of queries based on an array of "entities" that I made for this purpose.
To do this, I made a small class that contains the information needed to create a query called EntityContract
public class EntityContract {
public final SyncContract syncContract;
public final String entityName;
public final String endpoint;
public final Class<? extends ModelClass> modelClass;
public EntityContract(SyncContract syncContract, String entityName, String endpoint , Class<? extends ModelClass> modelClass)
{
this.syncContract = syncContract;
this.endpoint = endpoint;
this.entityName = entityName;
this.modelClass = modelClass;
}
public String getUrl()
{
return SyncContract.SERVICE_URL + "/" + endpoint;
}
}
In my SyncAdapter, I just iterate over an array of entityContracts objects to run a query one by one.
I have a problem when I try to parse the answer using Gson. (So this is not a Gson related question, I think. It's about Java semantics)
gson is waiting for a call in the following structure
List< ExampleModel > list = new Gson().fromJson( response.body().charStream() , new TypeToken<List<ExampleModel>>(){}.getType() );
or
ExampleModel[] list = new Gson().fromJson( response.body().charStream() , ExampleModel[] );
where "ExampleModel" was supposed to be replaced by a class from an entityContract, so he would read something like this:
List< myContract.modelClass > list = new Gson().fromJson( response.body().charStream() , new TypeToken<List<myContract.modelClass>>(){}.getType() ); // Won't compile!!!
, ? , ?
+4