The Oracle Java Style Guide states:
Modifiers should not be written out when they are implicit.
(See Modifiers in Oracle Official Code Standard for the context and a link to the actual Oracle document.)
This style guidance applies particularly to interfaces. Let's consider the following code snippet:
interface I {
public static final int VARIABLE = 0;
public abstract void method();
public static void staticMethod() { ... }
public default void defaultMethod() { ... }
}
All interface variables are implicitly constants with implicit public
(accessible for all), static
(are accessible by interface name) and final
(must be initialized during declaration) modifiers:
public static final int VARIABLE = 0;
public
and abstract
.public abstract void method();
static
or default
modifier must provide implementation and are implicitly public
.public static void staticMethod() { ... }
After all of the above changes have been applied, we will get the following:
interface I {
int VARIABLE = 0;
void method();
static void staticMethod() { ... }
default void defaultMethod() { ... }
}