2

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)

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Vinay, that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.