Java 接口(interface)中的方法是否应该在声明时使用或不使用 public
访问修饰符?
当然,从技术上讲,这并不重要。实现 interface
的类方法始终是 public
。但是什么是更好的约定呢?
Java 本身在这方面并不一致。例如,参见 Collection
与 Comparable
,或 Future
与 ScriptEngine
。
最佳答案
JLS清楚地表明这一点:
It is permitted, but discouraged as a matter of style, to redundantly specify the
public
and/orabstract
modifier for a method declared in an interface.
关于java - Java 接口(interface)中的方法是否应该使用或不使用公共(public)访问修饰符来声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/161633/