I have several interfaces like
interface CanFly{ .. }
interface CanRun{ .. }
and a lot of implementations (done by others)
class Dog implements CanFly{ .. }
class Duck implements CanFly, CanRun{ .. }
Now at some point I need to use a generic which requires types that implement two interfaces.
class FlyAndRunHandler <ANIMAL extends CanFly AND CanRun>{
void performAction(ANIMAL animal){
animal.fly();
animal.run();
}
}
In Scala it would look like ANIMAL extends CanFly with CanRun
. Is there a way to archive this in Java. If required I could write additional interfaces but there is no way to add them to the animal classes.