How to apply more constraints on an interface declaration in Java?

You could use generics and change your design.

Something in the lines of:

interface Marriable<T extends Mammal> {
    void marry(T sweetHalf);
    T giveBirthTo();
}

… where Mammal is your top interface or abstract class, and Human, Dog, Unicorn etc. extend / implement it.

Leave a Comment