I have an interface HTTPSequence
. I also have an abstract class AbstractHTTPFactory
which in turn has an abstract method returning ArrayList<HTTPSequence>
. In classes derived from AbstractHTTPFactory
I want to override those methods to return ArrayList<[Class implementing HTTPSequence]>
.
Is it possible ? Now compiler gives my an error suggesting that I change overriden methods signature to HTTPSequence
.
// abstract class with abstract method returning ArrayList of objects implementing interface
abstract public class AbstractHTTPFactory {
abstract ArrayList<HTTPSequence> make();
}
// Specific class that returns ArrayList of objects of the class implementing HTTPSequence
public class RecipesHTTPFactory extends AbstractHTTPFactory{
public ArrayList<Recipe> make() {
}
}
// interface
public interface HTTPSequence {
}
// one of the classes implementing the above interface
public class Recipe implements HTTPSequence {
}
And the message Eclipse gives me is:
Multiple markers at this line - The return type is incompatible with AbstractHTTPFactory.make() - implements ....ider.AbstractHTTPFactory.make