I have several interfaces, for example
interface CanFly{ .. }
interface CanRun{ .. }
and many implementations (made by others)
class Dog implements CanFly{ .. }
class Duck implements CanFly, CanRun{ .. }
Now at some point I need to use 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 will look like ANIMAL extends CanFly with CanRun. Is there a way to archive this in Java. If necessary, I could write additional interfaces, but there is no way to add them to animal classes.
source
share