Default Methods in Java 8
Default methods enable us to add new functionalities to interfaces without breaking the classes that implements that interface.
In my previous articles, we have looked at LambdaExpressions and Method References. In this latest article in the series, we will
be looking at Default
methods.
What is Default
method?
We specify that a method
definition in an interface is a default method with the default keyword
at the beginning of the method signature. All method declarations in an
interface, including default methods, are implicitly public, so you can omit the public modifier.
Extending Interfaces that contains default
methods
When you extend an interface that contains a default method,
you can do following:
- Not mention the default method at all, which lets your extended interface inherit the default method.
- Re declares the default method, which makes it abstract.
- Redefine the default method, which overrides it.
No comments:
Post a Comment