【发布时间】:2011-04-24 23:42:49
【问题描述】:
我正在尝试创建一些实现特定接口的类(在本例中为XYPlottable)和一个可以处理实现该接口的任何类的方法。
到目前为止,我有以下(有效):
public interface XYPlottable {
public Number getXCoordinate();
public Number getYCoordinate();
public Number getCoordinate(String fieldName);
}
public class A implements XYPlottable {
//Implements the above interface properly
...
}
public class B implements XYPlottable {
//Implements the above interface properly
...
}
这很好用。我还有一种方法可以尝试绘制 XYPlottable 的任何内容:
public static Frame createPlot(String title, String xAxisLabel, String yAxisLabel,
List<XYPlottable> points, boolean fitLine) {
所以我尝试将它与上述具体类之一一起使用,但它抱怨类型不兼容:
List<A> values = _controller.getValues(tripName);
XYPlotter.createPlot("Plot A", "B", "C", values, false);
这是确切的错误:
incompatible types
required: java.util.List<XYPlottable>
found: java.util.List<A>
我希望我只是有一点时间并错过了一些非常明显的东西,但也许我对应该如何使用接口有误解。
【问题讨论】: