【发布时间】:2012-04-12 10:57:47
【问题描述】:
我有一个接口HTTPSequence。我还有一个抽象类AbstractHTTPFactory,它又有一个抽象方法返回ArrayList<HTTPSequence>。在派生自AbstractHTTPFactory 的类中,我想重写这些方法以返回ArrayList<[Class implementing HTTPSequence]>。
有可能吗?现在编译器给了我一个错误,建议我将覆盖的方法签名更改为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 {
}
Eclipse 给我的信息是:
此行有多个标记 - 返回类型与 AbstractHTTPFactory.make() 不兼容 - 实现 ....ider.AbstractHTTPFactory.make
【问题讨论】:
-
你为什么只想返回一个非泛型的
ArrayList?这违背了泛型的目的! -
一些示例代码会很有帮助。
-
以及准确的编译器消息。挥手无济于事,@user971155