Tuesday, August 11, 2015

Default Methods

Default Methods in Java 8

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?

Default methods enable us to add new functionalities to interfaces without breaking the classes that implements that interface.

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

Java garbage collection

In this post , we ’ ll take a look at how garbage collection works , why it ’ s important in Java , and how it works in...