私はリファクタリングしているこのコードを持っています:
if (response != null) {
Type collectionType = new TypeToken<List<GameInfo>>() {}.getType();
Gson gson = new Gson();
return (List<GameInfo>) gson.fromJson(response, collectionType);
}
「リスト」部分が任意のコレクションタイプである関数を作成できますか?
違法コードの例:
private <T> T collectionFromJson(String pResponseJson, Class<T> pCollectionClass) {
T result = null;
Type collectionType = new TypeToken<pCollectionClass>() {
}.getType();
...
return result;
}
私が狙っているものを説明する違法なコードへの違法な呼び出しの例:
return collectionFromJson(response, List<GameInfo>.class);