Static & Private Interface Methods
Static & Private Interface Methods
Java 8 introduced default methods to interfaces. Two further additions completed the picture: static methods (Java 8) and private methods (Java 9). Together they let interfaces carry real utility logic without polluting the classes that implement them.
Static Methods in Interfaces
A static method in an interface belongs to the interface itself, not to any implementing class. You call it with the interface name, just like a static method on a class — InterfaceName.method().
Any class can call Validator.requireNonNull(email, "email") without having to implement Validator. Notice that the method is a helper that the interface ships with itself; implementing classes cannot override it.
EmailValidator implements Validator<String>, you cannot write EmailValidator.requireNonNull(...). The call must go through Validator.requireNonNull(...). This is intentional — it prevents ambiguity when a class implements multiple interfaces that each declare the same static method name.
Why Put Static Helpers on an Interface?
Before Java 8, the standard pattern was a companion utility class — think Collections alongside Collection, or Objects alongside Object. That works, but it separates related code into two files. Interface static methods let you keep the utility logic right next to the contract it supports:
DiscountUtils or Discounts helper class. The result is discoverable — any IDE that types Discount. shows the available factories immediately.
Private Methods in Interfaces (Java 9+)
Once default methods arrived, a problem quickly emerged: two default methods sometimes share duplicated logic, but there was nowhere to put a shared helper inside the interface without exposing it as part of the public contract. Java 9 solved this with private methods.
The format method is an implementation detail. Implementing classes never see it — it does not appear in the public API. If you later change the format string, you change one method instead of three.
Private Static Methods in Interfaces
You can also make a private method static. The rule mirrors what you already know from classes: a private instance method can only be called from other instance methods (default methods in this case), while a private static method can be called from both default and static methods.
default and static methods. Trying to call a private interface method from an implementing class is a compile-time error.
Putting It All Together
Here is a self-contained example that uses all four method kinds — abstract, default, static, and private — in a single interface:
Summary
- Static methods (Java 8) — belong to the interface, not instances; called via
Interface.method(); great for factory methods and pure helpers. - Private methods (Java 9) — visible only inside the interface; remove duplication across
defaultmethods. - Private static methods (Java 9) — same as private methods but callable from
staticmethods too. - Neither static nor private methods are part of the contract — implementing classes do not inherit or override them.