default
keyword was used to declare default values for annotation elements.With the introduction of Java 8, alongside lambdas and streams, there arose a pressing need to augment standard interfaces with new methods without breaking backward compatibility. The solution was to introduce default methods.
Adding the
default
keyword to an interface method now allows it to have a body. This enables old interfaces to be updated with new methods that come with a default implementation.In a method's implementation, it's default version can be invoked using the same syntax as calling an external class from a nested one:
InterfaceName.super.methodName()
.Default methods have moved Java a step closer to introducing a hassle-free version of multiple inheritance – mixins. Since interfaces cannot have state, full-fledged mixins are still unachievable.