Apologies if duplicate, don't know the right terminology for this question, so I didn't find anyone asking something similar.
I have two interfaces. Lets say Canine and Pet. Pet has a play method, which is abstract. Canine does NOT extend Pet. It has a default play method though, which matches the play method signature of Pet.
Dog is a class that implements both Canine and Pet. Dog would like to use Canine's default play method.
How would i go about implementing this cleanly? The only way I see is if I do something silly like this
class Dog implements Canine, Pet{
public Dog(){
}
@Override
public void play (String greeting) {
Canine.super.play(greeting);
}
}
interface Canine {
default void play (String greeting) {
System.out.println(greeting);
}
}
interface Pet {
void play (String greeting);
}
From what i can tell, in C++ you can declare that a class uses the default implementation of a method, instead of implementing it in said class. Is there a way to do something similar in java 8?