- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道接口(interface)方法是隐式的public
。 Java Docs Tutorial说
All
abstract
,default
, andstatic
methods in an interface are implicitlypublic
, so you can omit the public modifier.
在 abstract、static 和 default 之外,哪些修饰符在 Java 8 中被隐式声明。
我认为 abstract
不再隐式声明,因为 Java 8 在接口(interface)中引入了 default
方法,但我仍然收到 Intellij IDEA 中的警告 .
Modifier '
abstract
' is redundant for interface methods.
public interface TestInterface {
abstract int print(); // abstract redundant ?.
int print2(); //legal.but public or public abstract ?.
}
最佳答案
language spec - 特别是第 9.4 节,声明 abstract
和 public
是隐式的。
Every method declaration in the body of an interface is implicitly public (§6.6). It is permitted, but discouraged as a matter of style, to redundantly specify the public modifier for a method declaration in an interface.
An interface method lacking a default modifier or a static modifier is implicitly abstract, so its body is represented by a semicolon, not a block. It is permitted, but discouraged as a matter of style, to redundantly specify the abstract modifier for such a method declaration.
这就是 IntelliJ 警告您的原因;通过 JLS,您正在做一些完全多余的事情。
作为奖励,fields in interfaces是隐式的public static final
:
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.
关于java - Java 8 中接口(interface)方法的隐式说明符/修饰符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48889674/
我是一名优秀的程序员,十分优秀!