java代码中有有两个方法,方法体的代码一样,入参类型不一样,返回类型是各自的入参类型,该如何解藕?
代码如下
public static <T, F> void cutInParameter(LambdaQueryWrapper<T> wrapper, SFunction<T, ?> column, Collection<F> coll) {
List<List<F>> newList = splitList(coll, paramNums);
if (CollectionUtils.isNotEmpty(newList)) {
if(newList.size() ==1){
wrapper.in(column, newList.get(0));
}else{
wrapper.and(i -> {
i.in(column, newList.get(0));
newList.remove(0);
for (List<F> objects : newList) {
i.or().in(column, objects);
}
});
}
}else{
wrapper.eq(column, null);
}
}
public static <T, F> void cutInParameter(LambdaUpdateWrapper<T> wrapper, SFunction<T, ?> column, Collection<F> coll) {
List<List<F>> newList = splitList(coll, paramNums);
if (CollectionUtils.isNotEmpty(newList)) {
if(newList.size() ==1){
wrapper.in(column, newList.get(0));
}else{
wrapper.and(i -> {
i.in(column, newList.get(0));
newList.remove(0);
for (List<F> objects : newList) {
i.or().in(column, objects);
}
});
}
}
}
public void A(String a, String b){
A(b)
}
public void A(String b){
}
仅从代码来看,参数a的值并没有用到。所以直接将有两个形参的方法删去即可
在一个方法体中,将参数类型转换为另一个方法的参数类型,然后调用另一个方法
public void A(String a, String b){
// xxxxxx
}
public void A(String a){
// 默认值
A(a, null);
}