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
{
...
}
}
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.