Overriding the default interface method with an abstract method

It seems to me that this is strange, and I was wondering if this is what is regularly used. When can this be helpful?

public interface InterA { Object getInfo() throws Exception1; } public interface InterB { public default Integer getInfo(Object s) {return 67;} } public interface InterC extends InterA, InterB { @Override public abstract Integer getInfo(Object s); } 
+6
source share
2 answers

Of course, you are allowed to do this. The name itself says that it is abstract . You are allowed to do this when the implemented class of this abstract class must override this method.

When you decide to be abstract, you do not need to implement.

+1
source

This exists before the default interface methods. For example, an abstract class can do

  @Override abstract public int hashCode(); 

forced subclasses provide implementations for hashCode , possibly due to additional requirements imposed by the abstract class.

+1
source

All Articles