1

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

I want all subclasses implementing AbstractDDLOperation to pass different type of parameters, all extending from Artifact class to the methods alter, create and drop.

Can anyone give a suggestion about the issue?

Thanks.

1 Answer 1

3

Your class should implement DDLOperation<T>, not the raw 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.

7
  • Thanks it solved the problem, but I have another issue : when i call alter(artifact) in abstract class it gives another error : The method alter(T) in the type AbstractDDLOperation<T> is not applicable for the arguments (Artifact) . Any suggestions about this one?
    – Tuncer T.
    Commented Feb 9, 2020 at 12:19
  • @TuncerTunçer please edit your question to include that code that causes this error.
    – Eran
    Commented Feb 9, 2020 at 12:21
  • This is because you defined the interface to accept only T ( which happens to implement Artifact ), not any class that implements Artifact
    – Gonen I
    Commented Feb 9, 2020 at 12:28
  • @TuncerT. alter accepts an argument of type T, not any Artifact. If you instantiated your class (or actually some concrete sub-class of your abstract class) with new ConcreteDDLOperation<SomeArtifact>(), you'll only be able to pass SomeArtifact instances to alter(). Perhaps your createArtifact(childElement) method should be changed to return T (if possible).
    – Eran
    Commented Feb 9, 2020 at 12:32
  • @GonenI Artifact is only a super class for other types of artifacts, like Index, Table and etc. So if I understand correct, you say that, parameter to the method alter(artifact) should be a subclass, not a superclass. What happens if I cast the argument to Artifact?
    – Tuncer T.
    Commented Feb 9, 2020 at 12:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.