So, yes I’ve seen this question. However, what if I had two interfaces, IA and IB, but I wanted a parameter to a function (or property of a class) to be:
public void (<? extends IA, IB> someClass) {
//...
}
Is there a way to do this without using generics?
EDIT:
I’ve realized that what I really want is Duck Typing, like in Python. I just didn’t get my words out right. With that in mind, clearly there is no real way to do this in Java. I accepted this answer, but then realized that the input would have to have the signature of that new interface to work. However, he did meet my awkwardly-worded criteria :).
Since interfaces can extend multiple other interfaces, you can just make an empty ‘dummy interface’ that extends both of them, and use it as the type to designate whenever both are required.
This works, but is not a catch-all solution as it requires you to modify every single class that implements
IAandIBso they can work for this method, which is annoying at best and impossible in some situations. Unfortunately, I do not know of any other way to do this without generics.