What is the reason why “synchronized” is not allowed in Java 8 interface methods?

While at first it might seem obvious that one would want to support the synchronized modifier on default methods, it turns out that doing so would be dangerous, and so was prohibited. Synchronized methods are a shorthand for a method which behaves as if the entire body is enclosed in a synchronized block whose lock … Read more

Super class method and Interface default method conflict resolution

Your assumption is right, the concrete method inherited from the superclass takes precedence over the default method from the interface: JLS §8.4.8. Inheritance, Overriding, and Hiding A class C inherits from its direct superclass and direct superinterfaces all abstract and default (§9.4) methods m for which all of the following are true: … No method … Read more

Why is “final” not allowed in Java 8 interface methods?

This question is, to some degree, related to What is the reason why “synchronized” is not allowed in Java 8 interface methods? The key thing to understand about default methods is that the primary design goal is interface evolution, not “turn interfaces into (mediocre) traits”. While there’s some overlap between the two, and we tried … Read more

Explicitly calling a default method in Java

As per this article you access default method in interface A using A.super.foo(); This could be used as follows (assuming interfaces A and C both have default methods foo()) public class ChildClass implements A, C { @Override public void foo() { //you could completely override the default implementations doSomethingElse(); //or manage conflicts between the same … Read more