http://androidren.com/index.php?qa=322&qa_1=java-%E4%B8%AD-modifer-public-is-reduntant-for-interface-methods

常常会看到接口上写了public修饰方法,然后IDE,比方:Eclipse或者IDEA常常会提示public是多余的。后来就查了一下。java默认接口的方法是public和abstract的,所以真不是必需。同一时候,假设你使用private或者protected都会报错。

所以,安心删除public吧。

http://stackoverflow.com/questions/17011374/are-public-and-public-final-redundant-for-interface-methods

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 publicstatic,
and final. Once again, you can
omit these modifiers.

另外。全部常量值默认都是public static final,不用加入。

Java 中 modifer 'public' is reduntant for interface methods的更多相关文章

  1. Java中定义常量方法及建议(Class/Interface)

    Class定义常量方法(推荐方法) //final修饰符 public final class Constants { //私有构造方法 private Constants() {} public s ...

  2. C++/Java中继承关系引发的调用关系详解

    C++: 这里引用到了 http://blog.csdn.net/haoel/article/details/1948051/ 中的内容,还请提前阅读陈大神的这篇博客后在阅读本篇. 覆盖,实现多态的基 ...

  3. java中static方法的继承性

    首先需要知道的是,java中所有的public实例方法都默认是virtual的,static方法不是virtual的,所以static方法可以被覆盖(new),但不可被重写(override) 1.被 ...

  4. 深入理解Java 中SPI 制

    深入理解Java 中SPI 制 概述 SPI(Service Provider Interface),是JDK内置的一种服务提供发现机制,可以用来启用框架扩展和替换组件,主要是被框架的开发人员使用,比 ...

  5. 慕课网-安卓工程师初养成-3-9 Java中运算符的优先级

    来源 http://www.imooc.com/code/1315 所谓优先级,就是在表达式中的运算顺序.Java 中常用的运算符的优先级如下表所示: 级别为 1 的优先级最高,级别 11 的优先级最 ...

  6. Java中public,private,protected,和默认的区别

    Java中public,private,protected,和默认的区别 1.private修饰词,表示成员是私有的,只有自身可以访问: 2.protected,表示受保护权限,体现在继承,即子类可以 ...

  7. 详解Java中的访问控制修饰符(public, protected, default, private)

    Java中的访问控制修饰符已经困惑笔者多时,其中较复杂的情况一直不能理解透彻.今天下定决心,系统.全面地研究Java中的访问控制修饰符的所有方面,并整理成这篇文章,希望有同样疑惑的读者读完后能有所收获 ...

  8. java中关于public class

    在编写类的时候可以使用两种方式定义类:     public class定义类:     class定义类: 1,如果一个类声明的时候使用了public class进行了声明,则类名称必须与文件名称完 ...

  9. Java中private、protected和public作用域的异同

    Java中private.protected和public作用域的异同 说明:(1)private的作用范围为当前类,protected的作用范围哦不能超过其他包: (2)区别不同的作用域的不同作用范 ...

随机推荐

  1. React和webpack解决 waiting for roots to load...to reload the inspector

    使用chrome调试工具,react-devtools总是显示 "waiting for roots to load...to reload the inspector" and ...

  2. 下载kaggle数据集,验证手机号

    https://blog.csdn.net/Tomxiaodai/article/details/80167765 kaggle上下载一下数据集必须手机验证,结果验证时一直提示错误输入的格式错误,试了 ...

  3. phphstrom改变项目中文件排列方式

    1.View>Tool Win dows>Project 效果图: 2.File->settings (Ctrl+Alt+S)-> Editor->General-> ...

  4. find_in_set()和in()比较

    转载于:https://www.cnblogs.com/zqifa/p/mysql-4.html 作者:zqifa 因为自己太懒了,就从大佬那转载来,作为一次笔记! mysql 中find_in_se ...

  5. Swing实现个人简历

    源码: import java.awt.Container;import java.awt.FlowLayout;import java.awt.Font; import javax.swing.*; ...

  6. 计算几何——认识基本object:点、线、面 。

    认识基本object:点.线.面  一.点 点用P(x, y)来表示:如: typedef pair<double, double> _pair; _pair point[MAXN]; 二 ...

  7. 关于OpenMP的归约操作reduction

    这里提一个重要的点 像这样 ; void ff() { sum += 0.5; } //main() #pragma omp parallel for reduction(+:sum) ; i < ...

  8. MySQL与MyBatis中的查询记录

    1.时间段查询 MySQL:select * from table where ctime >= CURDATE() and ctime <DATE_SUB(CURDATE(),INTER ...

  9. c++基础_字母图形

    #include <iostream> #include <algorithm> using namespace std; int main(){ ,m=,c; cin> ...

  10. 集训第六周 数学概念与方法 UVA 11722 几何概型

    ---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...