# Private methods in interfaces in Java 9

DevFeed: [Private methods in interfaces in Java 9](<https://devfeed.tech/articles/private-methods-in-interfaces-in-java-9-21992.md>)

Original publisher: [Read original article](<http://blog.joda.org/2016/09/private-methods-in-interfaces-in-java-9.html>)

Author: Stephen Colebourne (noreply@blogger.com)

Published: 2016-09-20T06:26:00Z

Content type: tutorial

Language: en

Sources: [Stephen Colebourne](<https://devfeed.tech/sources/stephen-colebourne.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [Java 9](<https://devfeed.tech/topics/java-9.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [feature](<https://devfeed.tech/tags/feature.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [java](<https://devfeed.tech/tags/java.md>), [java-9](<https://devfeed.tech/tags/java-9.md>), [java9](<https://devfeed.tech/tags/java9.md>), [new-feature](<https://devfeed.tech/tags/new-feature.md>)

## AI overview

This article explains private methods on interfaces in Java 9. It contrasts them with the public abstract, static, and default methods supported in earlier Java versions and describes supported and invalid modifier combinations. Private interface methods may be static or instance methods and are not inherited by sub-interfaces or implementations.

## Source excerpt

Java SE 9 is slowly moving towards the finishing line. One new feature is private methods on interfaces. Private methods on interfaces in Java 9 In Java 7 and all earlier versions, interfaces were simple. They could only contain public abstract methods. Java 8 changed this. From Java 8, you can have public static methods and public default methods. public interface HolidayCalendar { // static method, to get the calendar by identifier public static HolidayCalendar of(String id) { return Util.holidayCalendar(id); } // abstract method, to find if the date is a holiday public abstract boolean isHoliday(LocalDate date); // default method, using isHoliday() public default boolean isBusinessDay(LocalDate date) { return !isHoliday(date); } } Note that I have chosen to use the full declaration, with "public" on all three methods even though it is not required. I have argued that this is best practice for Java SE 8, because it makes the code clearer (now there are three types of method) and prepares for a time when there will be non-public methods. And that time is very soon, as Java 9 is adding private methods on interfaces. public interface HolidayCalendar { // example of a private interface method private void validateDate(LocalDate date) { if (date.isBefore(LocalDate.of(1970, 1, 1))) { throw new IllegalArgumentException(); } } } Thus, methods can be public or private (with the default being public if not specified). Private methods can be static or instance. In both cases, the private method is not inherited by sub-interfaces or implementations. The valid combinations of modifiers in Java 9 will be as follow: public static - supported public abstract - supported public default - supported private static - supported private abstract - compile error private default - compile error private - supported Private methods on interfaces will be very useful in rounding out the functionality added in Java 8.