Learning java 8 default methods. This link, like any other resource on the Internet, says
In the strictest sense, the default methods are a step backwards because they allow you to “pollute your interfaces with code. But they provide the most elegant and practical way to backward compatibility. This has made it easy for Oracle to update all Collection Classes and for you to modify existing code for Lambda.
My understanding is that java 8 dev / designer provided a default method in the interfaces so that the entire implementing class does not need to unnecessarily override the same behavior, therefore, provide backward compatibility. For example: - if the ForEach method was not the default method, each collection implementation class should implement it. Agreed.
To overcome this, we could have one class that provides the default implementation of these methods, and then an implementation of a class such as an arraylist, etc. expanded it. Thus, we could affirm both the basic principles of java and reuse and abstraction, thereby reducing interface pollution
I am sure that java 8 dev / designer has already thought about this, since they are much more recognized, and I missed something. Could someone help here so that we developers can also be on top of this as this is a significant change?
source
share