Reputation: 21
What could be the thought process behind having static implementations in Interfaces (Java-8)?
(As these static methods are not inherited by implementing classes nor static methods can be overridden)
Upvotes: 2
Views: 38
Reputation: 7504
The purpose could be different from different perspectives but what Oracle says is below:
This makes it easier for you to organize helper methods in your libraries; you can keep static methods specific to an interface in the same interface rather than in a separate class.
Basically, it allows putting utility methods like null check, string manipulations etc within the interface itself. This basically eliminates the need of writing Utility classes or Wrapper classes with utility features.
As a examples Collections
utility class could go away and the utility methods could be put inside the interfaces itself.
For more read here at oracle.
Upvotes: 1