Now we know that Java 8 introduced interface and static methods in interfaces.
Interfaces were originally introduced in Java to avoid the diamond problem that occurred in C ++ in multiple inheritance.
But along with the introduction of default methods in interfaces in Java 8, now Java also introduced a diamond problem that it avoided in previous versions.
The default methods are not necessarily necessary to override.
But when the problem with the diamond is related to the use of interfaces, the class implementing these interfaces must override the default methods.
So now I have three questions:
- Why do we need default methods?
- Could we have multiple inheritance through classes, instead of using default methods in interfaces?
- And what was the need to avoid the problem with diamonds in previous versions, if they still had to present it in Java 8?
Any good explanation or any link for an explanation?
PS I did not find a link on the Internet containing any good article about this.
All they said is that an abstract class gives you more specificity.
As in the case, abstract classes can have constructors, but interfaces cannot.
So, I want to know if abstract classes are more specific and can have constructors,
and in any case, Java introduced a problem with diamonds, why should we have interfaces now? Won't abstract classes be good enough as independent classes for multiple inheritance?
source share