【发布时间】:2021-10-07 08:47:19
【问题描述】:
我使用 XML 文档。我的程序中有很多类似的标签和方法。它们都做同样的事情,但它们返回的所有东西都作为参数具有不同的对象。在这个方法中,我检查了两个字符串。因此,可以使用 T 来代替不同的对象。所有这些对象都没有连接。例如,我想做以下事情:
private <T> T checkBusinessEntityTypeCode(CheckDtKdt checkDtKdt, T kdtCode, T dtCode) {
if (kdtCode != null && dtCode != null) {
if (StringUtils.compare(kdtCode..getValue(), dtCode.getValue()) != 0) {
checkFieldsDtKdtService.save14Graph(checkDtKdt, dtCode.getValue(), kdtCode.getValue());
dtCode.setValue(kdtCode.getValue());
}
if (StringUtils.compare(kdtCode.getCodeListId(), dtCode.getCodeListId()) != 0) {
checkFieldsDtKdtService.save14Graph(checkDtKdt, dtCode.getCodeListId(), kdtCode.getCodeListId());
dtCode.setCodeListId(kdtCode.getCodeListId());
}
}
}
当然,这段代码不起作用。因为 get() 和 set() 方法。我可以使用类似的东西吗?
【问题讨论】: