Question

I have the following. If I keep the @Override, I get an error that the method must implement or override a supertype method. If I remove it, I get an error that the child class must implement the inherited abstract method. Why won't the below code work, and how can I make it do what I intend?

BaseClass.java:

public abstract class BaseClass
{
    ...
    protected abstract <T extends Inputs> T doStuff(T inputs);

    public abstract static class Inputs
    {
        ...
    }
}

ChildClass.java:

public class ChildClass extends BaseClass
{
    ...
    @Override
    protected Inputs doStuff(Inputs inputs)
    {
        return inputs;
    }

    public static class Inputs extends BaseClass.Inputs
    {
        ...
    }
}
Était-ce utile?

La solution

Try and:

public abstract class BaseClass<T extends BaseClass.Inputs>

and:

public class ChildClass extends BaseClass<ChildClass.Inputs>

Which means you need to change doStuff() so that it returns T (in BaseClass), without having a declared type variable:

public abstract T doStuff(T inputs);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top