What is Default, Defender or Extension Method of Java 8 with Example
Java 8 now allows you to add non-abstract method implementations to interfaces by utilizing the default and static keywords. Methods with default keywords are known as default methods or defender methods in Java. Before Java 8, it was virtually impossible to change an interface once published. Any change like the addition of a new method would have broken all clients. That's why when Java 8 decided to switch to internal iterator implementation using the forEach() method, they face the daunting challenge of breaking all implementation of the Iterable interface. Since backward compatibility is a top priority for Java engineers, and it wasn't practical to break all clients, they came up with the idea of the default method.
تعليقات
إرسال تعليق