[英]abstract class multiple inheritance
我有以下类的结构:
我有一个静态方法,它有一个返回类型A并返回B - 这没关系。 我想更改此方法,因此它仍然返回类型A ,但它返回D - 这会导致问题:
java.lang.Error: Unresolved compilation problem:
D cannot be resolved to a type
为什么会这样? 它们应该具有与父类不同的接口? 编辑:
这是我试图修改的方法
public static CodeFormatter createDefaultCodeFormatter(Map<String, ?> options) {
if (options == null)
options = CCorePlugin.getOptions();
return new CCodeFormatter(options);
}
它是CDT项目的一个类( http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=a83be9db5b41c0a593425798a2af91060588b38a )。 我试图返回MyFormatter而不是CCodeFormatter。 类CCodeFormatter( 我们的B在示例中 )扩展了CodeFormatter( 我们的A在示例中 )并且由抽象类MyFormatter( 或示例中的C )扩展,并且此类由类MyFormatter( 在示例中为D )扩展。 所以我将它的项目添加到必需的包(在MANIFEST.MF中),然后我导入它并返回新的MyFormatter(选项)。 最后,会发生此错误。
public static CodeFormatter createDefaultCodeFormatter(Map<String, ?> options) {
if (options == null)
options = CCorePlugin.getOptions();
return new MyFormatter(options);
}
“D”级
public class MyFormatter extends MyAbstractFormatter{
@Override
protected CodeFormatterVisitor getFormatterVisitor(DefaultCodeFormatterOptions preferences, int offset, int length) {
return new MyFormatterVisitor(preferences, offset, length);
}
}
和“C”级
public abstract class MyAbstractFormatter extends CCodeFormatter {
public MyAbstractFormatter() {
super();
}
public MyAbstractFormatter(DefaultCodeFormatterOptions preferences) {
super(preferences);
}
public MyAbstractFormatter(DefaultCodeFormatterOptions defaultCodeFormatterOptions, Map<String, ?> options) {
super(defaultCodeFormatterOptions, options);
}
public MyAbstractFormatter(Map<String, ?> options) {
super(options);
}
@Override
public void setOptions(Map<String, ?> options) {
super.setOptions(options);
}
@Override
public TextEdit format(int kind, String source, int offset, int length, int indentationLevel, String lineSeparator) {
return super.format(kind, source, offset, length, indentationLevel, lineSeparator);
}
}
好吧,问题似乎是循环依赖(而不是抽象类)。 我的项目依赖于CDT项目,我正在尝试将我的项目添加到该项目的必需包中,我正在使这个CDT项目依赖于我的项目。 (Altought Eclipse通常会检测到这个问题,这可能不是这种情况)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.