I’m programming with java.
Let’s say I have an “MyInterface” interface, and a “MyClass” abstract class.
I want to ensure that every class implementing the “MyInterface” interface is inherited from “MyClass”.
An inherited class from MyClass is perfectly able to NOT implement the “MyInterface” interface.
Is this possible ? Thanks.
I’m sorry if my english is bad but I’m french.
AFAIK, you can’t do this directly.
Generics let you say something like this, if it helps:
So, you can only call foo() with parameters that are both MyClass and MyInterface.
Or, why not have two abstract base classes?
Then, use MyInterfaceClass instead of MyInterface.
Or, if you just care about containers, write your own:
Then, you will get a deprecation warning any time you make a mistake.
But my question remains – what problem are you trying to solve? Can you use more descriptive names instead of “Class” and “Interface”? Perhaps the right solution is something completely different..