Java:接口中的varargs [英] Java: varargs in interface
本文介绍了Java:接口中的varargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public interface MyInterface {
public ArrayList<Double> f(ArrayList<Double>... args);
}
我收到警告:类型安全:潜在堆污染通过varargs参数paramOfChildren
。我可以用 @SuppressWarnings(unchecked)
来抑制此警告。
I get the warning: Type safety: Potential heap pollution via varargs parameter paramOfChildren
. I can suppress this warning with @SuppressWarnings("unchecked")
.
但是,在实现此接口的每个类中,我再次收到此警告。我想知道是否有一种方法可以为实现该接口的所有类禁止此警告。如果没有,是否有充分的理由我们不应该这样做?
However, in every class that implements this interface, I get this warning again. I wonder if there's a way to suppress this warning once for all the classes implementing the interface. If not, is there a good reason that we shouldn't do it?
推荐答案
你可以确定通用:
class DoubleList extends ArrayList<Double> {
private static final long serialVersionUID = 1L;
}
interface MyInterface {
public DoubleList f(DoubleList... args);
}
这篇关于Java:接口中的varargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文