java泛型beancopylist E:元素
K:键
N:数字
T:类型
V:值
S、U、V 等:多参数情况中的第 2、3、4 个类型
例⼦代码:
public static <T,S> List<S> copyList(List<T> fromList,Class<S> toObj) {
if (CollUtil.isEmpty(fromList)) {
<("Utils-->copyList:fromList is null or have'nt data");
return null;
}
if (null == toObj) {
<("Utils-->copyList:toObj is null");
return null;
}
List<S> toList = wArrayList();
字符串截取对象
fromList.forEach(f->{
S t = null;
try {
t = wInstance();
} catch (Exception e) {
e.printStackTrace();
}
toList.add(t);
});
return toList;
}
调⽤:
@Test
public void testCopyList() throws Exception {
List<DictDO> fromList = wArrayList(new DictDO("code1","name1"),new DictDO("code2","name2"));    List<DictPojo> toList = pyList(fromList, DictPojo.class);
Console.log("{},{}",toList.size(),CollUtil.isEmpty(toList));
if (null != toList && toList.size()>0) {
toList.forEach(d->{
Console.log(d);
});
}
}
输出:
2,false
DictPojo(code=code1, name=name1)
DictPojo(code=code2, name=name2)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。