In some of the code I'm working with, I have an existing third-party API that implements things that extend from A (and possibly not directly, but through X and, possibly, also implementing many other interfaces).
Now, for the code I'm working on, I have an IB interface that provides additional capabilities to what A. offers. Since such code does have a requirement that the object passed to it extends A and also implements IB, but there is no way to declare it for my member variables that I can think of. But choosing A or IB leads to many castings.
I think if A had / had an IA interface, it would allow this, but I cannot change A, or for my IB implementations I do not need to extend A (third-party code uses A and takes a lot of control, persistence, networking, user interaction etc.).
class Z {
private List<?what here?> items;
private void subscribe(? item) {
items.add(item);
}
public void doSomethingWithItems() {
...code thats requires facilities from A and IB...
}
source
share