http://androidren.com/index.php?qa=322&qa_1=java-%E4%B8% Ad-modifer-public-is-reduntant-for-interface-methods
It is often seen that the public modifier is written on the interface, and then the IDE, for example: Eclipse or idea often prompts public to be redundant. Then I looked it up a bit. The Java default interface method is public and abstract, so it is not required. At the same time, assume that you use private or protected will error.
So, feel relieved to delete the public bar.
Http://stackoverflow.com/questions/17011374/are-public-and-public-final-redundant-for-interface-methods
You cannot has afinal
Method declared in an interface. Fields is alwaysfinal
But methods is alwaysabstract
(And neverfinal
). You cannot define an interface method, which is to be implemented only by classes in the same package.* FROM section 9.3 of the Java Language specification:
every Field declaration in the body of a interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of the these modifiers for such fields.
and from section 9.4:
Every method declaration in the body of a interface is implicitly public (§6.6).
Every method declaration in the body of an interface are implicitly abstract, so it body is always represented by a Semico Lon, not a block.
It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a me Thod declared in an interface.
* As Paul Bellora points out in a comment, you can make the interface itself package-private (or protected, or even privat e) If you want to restrict its visibility.
In addition, an interface can contain constant declarations. All constant values defined in an interface is implicitlypublic
, static
, andfinal
. Once again, you can omit these modifiers.
Other than that. All constant values are public static final by default, not joined.
Java Modifer & #39;p ublic& #39; is reduntant for interface methods