/**
* 根据指定的类型(targetClazz)实例化一个bean,并将source bean的属性赋值给实例化的bean
*
* @param source
* @param targetClazz
* @return
*/
public static <T> T beanUtils(Object source, Class<T> targetClazz) {
T target = null;
try {
target = targetClazz.newInstance();
} catch (Exception e) {
throw new RuntimeException("实例化" + targetClazz + "失败!");
}
BeanUtils.copyProperties(source, target);
return target;
}
最近用到的一个java方法泛型
最新推荐文章于 2022-08-02 17:01:12 发布