I use intellij IDEA 14.
I've got the following problem. Let the class ClassA
be implemented from interface A
, class ClassB
be implemented from interface B
and class ClassC
be implemented from interface C
.
Interface A
has method Object method (B b, C c) {...}
but I can't create an interface object, so I solved to override this method Object method(...) {...}
in my class ClassA
like that:
...
@Override
Object method (ClassB b, ClassC c) { // But here compiler writes an error "method does not override method from its superclass"
...
}
...
But it can't be compiled because of method does not override method from its superclass
. But why? Why we can use, for example, HashMap which is implemented from Map?
Thank you!
You just don't do that.
Imagine if, for example, you have two more classes. ClassB2 implements B
and ClassC2 implements C
. Your method wouldn't be applicable to parameters (ClassB2 b2, ClassC2 c2)
while Object method (B b, C c)
would be OK with it. And there, you have inconsistency between interface and implementation.