Java 8 default method
summary
Java 8 adds default methods for interfaces. Use the default keyword.
The default method is that the interface can have implementation methods, and no implementation class is required to implement its methods. Relative to jdk1 For the interface before 8, the method that can be implemented in the interface is added.
It can be said that part of the reason for implementing methods in the interface is to serve lambda expressions, because lambda expressions can only be handed over to the interface.
classification
grammar
Multiple default methods
Because there are default methods in the interface, a class can implement multiple interfaces. It is inevitable to encounter methods with the same name. When a class implements multiple interfaces and there are default methods with the same name in multiple interfaces, subclasses need to be re implemented to avoid ambiguity
Static default method
Java 8 interfaces can support static methods and provide implementations.