我有什么:
Type dogType = new TypeToken<ArrayList<Dog>>() {}.getType();
ArrayList<Dog> dogList = context.deserialize(jsonObject.get("dog"), dogType);
HashMap dogMap=new HashMap();
for (int i=0; i<dogList.size(); i++) {
Dog item = dogList.get(i);
dogMap.put(item.getId(), item);
}
home.setDogs(dogMap);
我想得到什么:
home.setDogs(getMap(jsonObject, "dog", Dog.class));
private HashMap<???> getMap(JSONObject jsonObject, String name, ??? type) {
ArrayList<???> list = context.deserialize(jsonObject.get(name), new TypeToken<ArrayList<type>>() {}.getType());
HashMap map=new HashMap();
for (int i=0; i<list.size(); i++) {
??? item = list.get(i);
map.put(item.getId(), item);
}
return map;
}
有可能吗?我需要设置而不是&#34; ???&#34;?