Compilation problem with overriding method
Hi,
I have a class with these 2 methods:
public Token clone() {
return clone(this.getAnnotation(), null);
}
@Override
public Token clone(Annotation annot, Map oAllreadyAddedAnnots) {
return new Token(this, annot); //
}
The superclass has the following method:
public abstract AnnotationData clone(Annotation annot, Map oAllreadyAddedAnnots);
class Token is a subclass of AnnotationData.
This does not compile with IntelliJ Idea: the compiler complains, for method clone() in the subclass, that it returns AnnotationData instead of Token. Apparently, the compiler looks at the superclass method with the 2 arguments, not at the method in the subclass.
I agree this is a tricky case, but it does compile in the latest version of Eclipse, using a recent jdk 1.6.
Could IntelliJ Idea be adapted for compiling this? Thanks for your feedback.
请先登录再写评论。
Hi Frederik,
Following code compiles fine for me. Testes under IJ 9.0.3 CE, jdk 1.6:
Regards, Denis
Denis,
your code is not the same as mine. Does it still compile if you call the second clone method in the subclass from the first one? So:
This won't compile, and I think it should...
Yes, it is compiled fine at IJ 9.0.3 CE, jdk 1.6.
Please provide information about your IntelliJ IDEA version that causes problems and try it with free Community Edition v.9.0.3.
Regards, Denis