[英]Using generics as method parameter Java
I have an interface :我有一个界面:
public interface DDLOperation <T extends Artifact> {
public void alter(T artifact);
public void create(T artifact);
public void drop(T artifact);
}
I also have an abstract class implementing that interface :我还有一个实现该接口的抽象类:
public abstract class AbstractDDLOperation <T extends Artifact> implements DDLOperation {
@Override
public abstract void alter(T artifact);
@Override
public abstract void create(T artifact);
@Override
public abstract void drop(T artifact);
public void processChildElement(Element childElement) {
Artifact artifact = createArtifact(childElement);
alter(artifact);
}
}
Eclipse gives this error in AbstractDDLOperation class : The method alter(T) of type AbstractDDLOperation must override or implement a supertype method Eclipse 在 AbstractDDLOperation 类中给出此错误:AbstractDDLOperation 类型的方法 alter(T) 必须覆盖或实现超类型方法
I want all subclasses implementing AbstractDDLOperation to pass different type of parameters, all extending from Artifact class to the methods alter, create and drop.我希望所有实现 AbstractDDLOOperation 的子类都传递不同类型的参数,所有这些参数都从 Artifact 类扩展到方法 alter、create 和 drop。
Can anyone give a suggestion about the issue?任何人都可以就这个问题提出建议吗?
Thanks.谢谢。
Your class should implement DDLOperation<T>
, not the raw DDLOperation
.你的类应该实现
DDLOperation<T>
,而不是原始的DDLOperation
。
It should be:它应该是:
public abstract class AbstractDDLOperation <T extends Artifact> implements DDLOperation<T>
Otherwise, your abstract class's methods don't override or implement any of the super type (interface) methods, so the @Override
annotation is incorrect.否则,您的抽象类的方法不会覆盖或实现任何超类型(接口)方法,因此
@Override
注释是不正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.