This is my overall workflow. First create an interface:
public interface foo {
void bar(Baz b);
}
Then make, for example, a vector with different objects that all implement said interface:
myVector.add(new Ex); //both Ex and Why implement foo.
myVector.add(new Why);
And finally, use the interface:
for(int i=0; i<myVector.size(); i++) {
myVector.get(i).bar(b);
}
However, for obvious reasons, this produces a compile time error:
The method bar() is undefined for the type Object
Casting won’t work because Ex and Why aren’t related. Try-catch casting to Ex and then Why is a horrible work-around. Making both Ex and Why extend Bar_doers also doesn’t sound succinct either, as that would be doing away with interfaces.
How can I perform operations that care about whether an Object implements a given interface, not whether an object is of a given class?
You need to read about generics.
Assuming you were using a standard Java container, then the solution in your case is to define
myVectorthus: