我正在尝试创建通用函数以最大程度地减少重复代码。我有以下功能(没有应用通用)
public ModelClass getModelDataList (String arg1)
{
ModelClass objModelClass = new ModelClass(new JSONObject(arg1));
return objModelClass;
}
所以现在我正在尝试使其通用,以便我可以使用任何 ModelClass(例如学生、部门、学院等),所以我通过在 Google 上搜索找到了代码
public static <T> T f(String response)
{
T typeList = new T(new JSONObject(response));
return typeList ;
}
有人可以告诉我如何实现这一目标。
提前致谢。