O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting ready

Private methods in an interface are new in Java 9. They allow you to make interface methods (with a body) accessible only to other methods (with a body) in the same interface.

A private method in an interface cannot be overridden anywhere--not by a method of any interface, nor by a method in any class. Its only purpose is to contain functionality that is common between two or more methods with a body, either private or public, in the same interface. It can also be used by one method only in order to make the code easier to understand.

A private interface method must have an implementation. A private interface method not used by other methods of the same interface does not make sense.

A static private interface method can be ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required