Java 中 modifer 'public' is reduntant for interface methods
Posted yangykaifa
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 中 modifer 'public' is reduntant for interface methods相关的知识,希望对你有一定的参考价值。
常常会看到接口上写了public修饰方法,然后IDE,比方:Eclipse或者IDEA常常会提示public是多余的。后来就查了一下。java默认接口的方法是public和abstract的,所以真不是必需。同一时候,假设你使用private或者protected都会报错。
所以,安心删除public吧。
You cannot have a final
method
declared in an interface. Fields are always final
but
methods are always abstract
(and
never final
).
You cannot define an interface method that 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 an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.
and from section 9.4:
Every method declaration in the body of an interface is implicitly public (§6.6).
Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block.
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.
* As Paul Bellora points out in a comment, you can make the interface itself package-private (or protected, or even private) if you want to restrict its visibility.
In addition, an interface can contain constant declarations. All constant values defined in an interface are implicitly public
, static
,
and final
. Once again, you can
omit these modifiers.
另外。全部常量值默认都是public static final,不用加入。
以上是关于Java 中 modifer 'public' is reduntant for interface methods的主要内容,如果未能解决你的问题,请参考以下文章
Flask報錯 KeyError 'SQLALCHEMY_TRACK_MODIFICATIONS'.md
KeyError: 'SQLALCHEMY_TRACK_MODIFICATIONS' 报错
make: Warning: File `led.c' has modification time 15 s in the future
make: Warning: File `Makefile' has modification time 1.8e+06 s in the future
编译在X86平台下运行的linux内核出错 make: Warning: File `.config' has modification time 6.5e+02 s in