I have a couple of interfaces:
public interface Speaker {
void speak();
}
public inteface Walker {
void walk();
}
I want a method that takes instances that are both a Speaker
and a Walker
.
Now, I could implement another interface:
public interface WalkerSpeaker extends Walker, Speaker {
}
And accept that:
void walkAndTalk(final WalkerSpeaker x) {
x.walk();
x.speak();
}
But this is quite cumbersome with many combinations, and every implementation must inherit from WalkerSpeaker
for it to work!
Is there a better way?