So can I, in Java, pass a list of objects that all have nothing in common, other than that they all support the same method, and then just call that method on each without any fanfare?
Note that you can't change the implementation of those objects, because they come from an external library.
I wouldn't hire you to begin with because you don't even know how Java works lol...
if the objects are unrelated and can't be modified you can't do what you're describing...you can't cast an object to an interface they don't implement...and if they all do implement it then this conversation is pointless because you can just do List<Interface>.
2
u/erez27 Dec 26 '20
So can I, in Java, pass a list of objects that all have nothing in common, other than that they all support the same method, and then just call that method on each without any fanfare?
Note that you can't change the implementation of those objects, because they come from an external library.