6.12---前提两个对象的成员必须一致,才能将有数据的对象将数据传给反射获取的对象conver(有数据对象,目标对象)

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.yx.AIHome.AIHome_common.base.utils;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.BeanUtils;

public class ConvertUtils {
public ConvertUtils() {
}

public static <T> T convert(Object src, Class<T> destClass) {
try {
T result = destClass.newInstance();
BeanUtils.copyProperties(src, result);
return result;
} catch (Exception var3) {
throw new RuntimeException(var3.getMessage(), var3);
}
}

public static <T> List<T> convert(List<?> srcList, Class<T> destClass) {
List<T> resultList = new ArrayList();
Iterator var3 = srcList.iterator();

while(var3.hasNext()) {
Object src = var3.next();
T dest = convert(src, destClass);
resultList.add(dest);
}

return resultList;
}
}
上一篇:对象引用 可变性 垃圾回收


下一篇:终于明白 Java 为什么要加 final 关键字了!