Even though this is mostly opinion, there is one thing you should remember:
public class Child extends Parent implements MyInterface {
public static void main(String[] args) {
Child c = new Child();
c.logSomething("toLog");
}
}
Let's check this for all possible scenario's:
First, there is such a method in the Parent class, not in the interface.
public class Parent {
public void logSomething(String toLog) {
System.out.println("Parent: " + toLog);
}
}
public interface MyInterface {
}
Obviously, the result will be:
Parent: toLog
Second scenario, the code is provided by the interface, not the class.
public class Parent {
}
public interface MyInterface {
default void logSomething(String toLog) {
System.out.println("Interface: " + toLog);
}
}
Here, it will also work, and the result will be:
Interface: toLog
But, when both provide it:
public class Parent {
public void logSomething(String toLog) {
System.out.println("Parent: " + toLog);
}
}
public interface MyInterface {
default void logSomething(String toLog) {
System.out.println("Interface: " + toLog);
}
}
The result will be:
Parent: toLog
Are you 100% sure there is no parent class, and there never will be one (that might provide (or inherit itself)) an implementationf or that method signature? Then it's a free choice.
On the other hand, if you opt for a default method, and someone does decide to add a parent class, that might lead to some stressful debugging.