Should methods in a Java interface be declared with or without a public access modifier?

Benno Richters picture Benno Richters · Oct 2, 2008 · Viewed 109.5k times · Source

Should methods in a Java interface be declared with or without the public access modifier?

Technically it doesn't matter, of course. A class method that implements an interface is always public. But what is a better convention?

Java itself is not consistent in this. See for instance Collection vs. Comparable, or Future vs. ScriptEngine.

Answer

Jon Skeet picture Jon Skeet · Oct 2, 2008

The JLS makes this clear:

It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface.