[英]abstract class multiple inheritance
I have following structure of classes: 我有以下类的结构:
I have a static method which has a return type A and returns B - this is ok. 我有一个静态方法,它有一个返回类型A并返回B - 这没关系。 I want to change this method, so it still has return type A , but it returns D - this causes problems: 我想更改此方法,因此它仍然返回类型A ,但它返回D - 这会导致问题:
java.lang.Error: Unresolved compilation problem:
D cannot be resolved to a type
Why is this happening? 为什么会这样? They should have the same interface as the parent classes don't they? 它们应该具有与父类不同的接口? Edit: 编辑:
This is the method im trying to modify 这是我试图修改的方法
public static CodeFormatter createDefaultCodeFormatter(Map<String, ?> options) {
if (options == null)
options = CCorePlugin.getOptions();
return new CCodeFormatter(options);
}
It is a class from the CDT Project ( http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=a83be9db5b41c0a593425798a2af91060588b38a ). 它是CDT项目的一个类( http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=a83be9db5b41c0a593425798a2af91060588b38a )。 Instead of CCodeFormatter I am trying to return MyFormatter. 我试图返回MyFormatter而不是CCodeFormatter。 Class CCodeFormatter ( our B in example ) extends CodeFormatter ( our A in example ) and is extended by abstract class MyFormatter ( or C in example ) and this class is extended by class MyFormatter ( D in example ). 类CCodeFormatter( 我们的B在示例中 )扩展了CodeFormatter( 我们的A在示例中 )并且由抽象类MyFormatter( 或示例中的C )扩展,并且此类由类MyFormatter( 在示例中为D )扩展。 So I add its project to required bundles (in MANIFEST.MF) and then I import it and return new MyFormatter(options). 所以我将它的项目添加到必需的包(在MANIFEST.MF中),然后我导入它并返回新的MyFormatter(选项)。 In the end, this error happens. 最后,会发生此错误。
public static CodeFormatter createDefaultCodeFormatter(Map<String, ?> options) {
if (options == null)
options = CCorePlugin.getOptions();
return new MyFormatter(options);
}
the "D" class “D”级
public class MyFormatter extends MyAbstractFormatter{
@Override
protected CodeFormatterVisitor getFormatterVisitor(DefaultCodeFormatterOptions preferences, int offset, int length) {
return new MyFormatterVisitor(preferences, offset, length);
}
}
and "C" class 和“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);
}
}
Ok, problems seems to be in cyclic dependency (and not in abstract classes). 好吧,问题似乎是循环依赖(而不是抽象类)。 My project is dependent on CDT project and I am trying to add my project to this project's required bundles, I am making this CDT project dependent on my project. 我的项目依赖于CDT项目,我正在尝试将我的项目添加到该项目的必需包中,我正在使这个CDT项目依赖于我的项目。 (Altought Eclipse usually detects this problem, this is probably not the case). (Altought Eclipse通常会检测到这个问题,这可能不是这种情况)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.