2017-11-11 133 views
0
public abstract class VfNetCallback<T> extends AbsCallback<VfNetResponse<T>> { 

    @Override 
    public VfNetResponse<T> parseNetworkResponse(Response response, int id) throws Exception { 
    VfNetResponse<T> netResponse = JSON.parseObject(response.body().toString(), VfNetResponse<T>.class); 
    return netResponse; 
    } 
} 

的我可以用如何獲取類VfNetCallback <T>

Class<T> dataClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; 

拿到類的T。但是我怎樣才能獲得VfNetResponse<T>的課程?

回答

0

終於,我找到了解決方案。

@Override 
public VfNetResponse<T> parseNetworkResponse(Response response, int id) throws Exception { 
    Type dataType = ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; 
    Type type = new ParameterizedTypeImpl(new Type[]{dataType}, null, VfNetResponse.class); 
    VfNetResponse<T> netResponse = JSON.parseObject(response.body().string(), type); 
    return netResponse; 
}