正如我们知道如果我们想重载现有方法,我们应该以某种方式更改参数数量或参数类型。这里是我的困境,我想使用过载与集类型结合不同亚型设置类型参数的Java方法过载
private boolean usedOverlap(Set<Variable> useVars, Set<Value> list) {
// TODO Auto-generated method stub
for(Variable use:useVars){
if(list.contains(use.getValue()))
return true;
}
return false;
}
private boolean usedOverlap(Set<Value>vaset_A,Set<Value>vaset_B){
Set<Value>intersection = new HashSet<Value>(vaset_A);
intersection.retainAll(vaset_B);
if(intersection.isEmpty())
return false;
else
return true;
}
那还有我怎么能在这种情况下,使用上述超载的问题。 对于第一个参数 在第一种方法:设置 第二种方法:设置
的区别是什么,到底是什么?就我所知,超载的问题是没有一个? –
在第一种方法中,我们使用Set,其次我们使用Set –
我认为你不能这样做。因为在运行时,类型将被删除,使这两个函数具有相同的方法参数(两个“Set”) –