Hi, Java lovers!
The problem: Java allows redundant modifiers in interface declarations.
public interface Foo {
public void Bar();
}
Interface method declarations in Java are implicitly public and abstract. So public modifier for Bar in this snippet is redundant.
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.
The possible solution: checkstyle has a builtin check for redundant modifiers.
I've checked all Java files in Chromium main repo and it looks there are around 700 redundant modifiers now.
Pros:
1. More consistency in code.
2. No more annoying warnings from IDEs.
Cons:
1. This check is triggered for the cases where redundant modifiers arguably increase readability:
public interface Foo {
public static final int BAR = 0;
}
Every field declaration in interface is implicitly public, static and final, so all these modifiers are redundant.
Some feedback on
this proposal contained requests to add this rule to clang-format style settings. It would be good to have clang-format auto-fix this, but I don't see anything similar in its style options. From this it looks like they would like to keep up with the style guides of major projects, but I think it would require adding this rule to the checkstyle config (and style guide) first.
Thanks in advance for your feedback.