Interfaces and extended classes

Hi all,

I found a problem when using the Implement method or Goto implementation on interfaces.

In my case there are 2 interfaces (A, B) with the same body. These interfaces are used in a service oriented environment, and the interface name is used as identification. Therefore 2 interfaces with the same body...

The implementation of these interfaces is also the same and is defined in one Abstract class that does not implement the interfaces. Instead the interfaces are implemented in a subclass of the Abstract class. There are 2 subclasses, 1 for each interface.


interface A {
someMethod();
}
interface B {
someMethod();
}

abstract class Main {
someMethod() {
body;
}
abstractMethod();
}

class AImpl extends Main implements A {
abstractMethod() {
bodyForA;
}
}

class BImpl extends Main implements B {
abstractMethod() {
bodyForB;
}
}

In this case intellij doesn't "find" the implementation of the interface methods. And if I try to do "implement method SomeMethod()" on either of the interfaces there are no classes found that can be used to implement the method in.

Can this be fixed?

TiA

Alexander

4 comments
Comment actions Permalink

Alexander,

How about this:

-


interface C { someMethod(); }

interface A extends C {}
interface B extends C {}

abstract class Main implements C {
someMethod() { body; }
abstractMethod();
}

class AImpl extends Main implements A {
abstractMethod() { bodyForA; }
}

class BImpl extends Main implements B {
abstractMethod() { bodyForB; }
}
-



Tim

0
Comment actions Permalink

The problem isn't with the code. That works ok. The problem is that Idea doesn't resolve the implementation path correctly. The code builds without any problem.

And I can't change the structure since it isn't "my" code. Though you solution would solve the problem that Idea has with it.

Thx for the reply,

Alexander

0
Comment actions Permalink

Yeah, I knew that you were looking for an IDEA fix.

I responded because your class hierarchy was a bit confusing and my suggestion would make it
easier for developers to understand as well as IDEAs handling of it.

As for "And I can't change the structure since it isn't "my" code." I feel your pain. I am
eternally in that situation, but it doesn't stop me from making suggestions.

Tim

0
Comment actions Permalink

No problem with posting suggestions :). I like them, and they make me look at code from a different side sometimes.

Someone from jetbrains read this and have any comment on a fix?

Alexander

0

Please sign in to leave a comment.