视频网站建站免费,做网站需要多少钱西安,wordpress 建立模型,页面布局怎么设置在java编程时#xff0c;经常会使用反射去处理对象#xff0c;有时会需要知道List的泛型类型#xff1a;示例操作如下
obj pojo.newInstance();// 首先得到pojo所定义的字段Field[] fields pojo.getDeclaredFields();for (Field curField : fields) {// 设置字段可访问经常会使用反射去处理对象有时会需要知道List的泛型类型示例操作如下
obj pojo.newInstance();// 首先得到pojo所定义的字段Field[] fields pojo.getDeclaredFields();for (Field curField : fields) {// 设置字段可访问必须否则报错curField.setAccessible(true);Class? curFieldType curField.getType();// 集合List元素if (curFieldType.equals(List.class)) {// 当前集合的泛型类型Type genericType curField.getGenericType();if (null genericType) {continue;}if (genericType instanceof ParameterizedType) {ParameterizedType pt (ParameterizedType) genericType;// 得到泛型里的class类型对象Class? actualTypeArgument (Class?)pt.getActualTypeArguments()[0];ListObject curEleList new ArrayList();Object actualType actualTypeArgument.newInstance();//....actualType字段处理curEleList.add(actualType); curField.set(obj, curEleList);}}}