1

Say here I have an Java interface Eat:

public interface Eat {
    default void eat(Meat meat) {}

    @Deprecated
    default void eat(Meat meat, Mood mood) {}
}

And I have an abstract class implements only one method in the interface:

public abstract class DogBase implements Eat {
    @Override
    public void eat(Meat meat) {}
}

And I have a class extends the abstract class:

public class Dog extends DogBase {

}

Then I found that in the unit test for Dog class, the deprecated method:

@Deprecated
default void eat(Meat meat, Mood mood) {}

defined in the interface Eat can be called by an object of Dog class.

Why is this possible? In my understanding, the abstract class DogBase only implements the non-deprecated method defined in the interface so that class Dog should not have the deprecated method.

OEurix
  • 393
  • 4
  • 19

0 Answers0