Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using subtype for parameter in method override

public abstract class SequenceItemHolder {

    public SequenceItemHolder(View itemView) {
    }

    public abstract void setData(SequenceRowElement.RowElement rowElement);


        public static class TesteItemHolder extends SequenceItemHolder {

        public TesteItemHolder(View itemView) {
        }

        @Override
        public void setData(SequenceRowElement.TestRowElement rowElement) {
        }
   }
}

Please can somebody explain me why do I get a compile error in the override?

Please how to fix it (without using an interface)?


NOTE: TestRowElement extends RowElement

like image 607
Lisa Anne Avatar asked Jun 04 '26 01:06

Lisa Anne


1 Answers

Error 1

public SequenceItemHolder(View itemView) {
    super(itemView);
    }

Object doesn't have a constructor taking a View as parameter. Remove the super call.

Error 2

public abstract void setData(SequenceRowElement.RowElement rowElement) {}

abstract methods should not have a body. replace it with this:

public abstract void setData(SequenceRowElement.RowElement rowElement);

Error 3

Your overriden method should have the same parameter type as the abstract one.

like image 83
Stultuske Avatar answered Jun 06 '26 15:06

Stultuske