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的更多相关文章
- Java中定义常量方法及建议(Class/Interface)
Class定义常量方法(推荐方法) //final修饰符 public final class Constants { //私有构造方法 private Constants() {} public s ...
- C++/Java中继承关系引发的调用关系详解
C++: 这里引用到了 http://blog.csdn.net/haoel/article/details/1948051/ 中的内容,还请提前阅读陈大神的这篇博客后在阅读本篇. 覆盖,实现多态的基 ...
- java中static方法的继承性
首先需要知道的是,java中所有的public实例方法都默认是virtual的,static方法不是virtual的,所以static方法可以被覆盖(new),但不可被重写(override) 1.被 ...
- 深入理解Java 中SPI 制
深入理解Java 中SPI 制 概述 SPI(Service Provider Interface),是JDK内置的一种服务提供发现机制,可以用来启用框架扩展和替换组件,主要是被框架的开发人员使用,比 ...
- 慕课网-安卓工程师初养成-3-9 Java中运算符的优先级
来源 http://www.imooc.com/code/1315 所谓优先级,就是在表达式中的运算顺序.Java 中常用的运算符的优先级如下表所示: 级别为 1 的优先级最高,级别 11 的优先级最 ...
- Java中public,private,protected,和默认的区别
Java中public,private,protected,和默认的区别 1.private修饰词,表示成员是私有的,只有自身可以访问: 2.protected,表示受保护权限,体现在继承,即子类可以 ...
- 详解Java中的访问控制修饰符(public, protected, default, private)
Java中的访问控制修饰符已经困惑笔者多时,其中较复杂的情况一直不能理解透彻.今天下定决心,系统.全面地研究Java中的访问控制修饰符的所有方面,并整理成这篇文章,希望有同样疑惑的读者读完后能有所收获 ...
- java中关于public class
在编写类的时候可以使用两种方式定义类: public class定义类: class定义类: 1,如果一个类声明的时候使用了public class进行了声明,则类名称必须与文件名称完 ...
- Java中private、protected和public作用域的异同
Java中private.protected和public作用域的异同 说明:(1)private的作用范围为当前类,protected的作用范围哦不能超过其他包: (2)区别不同的作用域的不同作用范 ...
随机推荐
- flutter 实现圆角头像的2种方法
圆角头像在开发中应用太普遍了,我总结了2种实现方法,分享给大家 方法一: 使用Container组件的decoration可以实现 Container( width: 40, height: 40, ...
- vue 发布build 本地设置 相对路径 两个地方 一个根目录用./ css文件里面用../../ 【也不好用,还是得手改】
build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths a ...
- Vue+Bootstrap实现购物车程序(3)
效果展示:(说明:使用webpack重构购物车程序,使用vue-cli生成项目脚手架) 文件结构: 代码: (1)将原来编写的btn-grp组件单独编写到BtnGrp.vue文件中 可以看到现在代码清 ...
- GNU编译器学习 --> 如何链接外部库【Linking with external libraries】
库也就是我们常说的library,一个库是若干个已经编译过的目标文件(.obj)的集合,它可以被链接到程序里.那么我们最常见的使用就是,我们在编程时会调用一些函数,这些函数别人已经写好了,它就放在库里 ...
- 一次ORA-01555问题分析,及SQL优化。
前言 客户说: 我在数据库上继续运行昨日的脚本,但发现有个子过程在运行10个小时后报错: 烦请协助看看... 错误码是:ORA-01555: snapshot too old: rollback se ...
- CentOS虚拟机挂载Windows共享目录
Windows文件共享使用了SMB协议(又称CIFS协议),该协议主要提供了文件共享和打印共享功能,分别使用TCP 139和445端口.UNIX.Linux系统提供了该协议的开源实现samba.为了方 ...
- Bash的循环结构(for和while)
在bash有三中类型的循环结构表达方法:for,while,until.这里介绍常用的两种:for和while. for bash的for循环表达式和python的for循环表达式风格很像: for ...
- PHP:压缩 Zip
文章来源:http://www.cnblogs.com/hello-tl/p/7661222.html <?php # 文件字符集 header("Content-type: text ...
- pip 打包项目配置库
打包项目中配置库(filename为文件名,可修改) pip freeze > filename.txt 安装配置文件中所有的库包 pip install -r filename.txt 如提示 ...
- socket scoketserver
import socket sk = socket.socket() # 创建了一个socket对象 # sk.setsockopt(socket.SOL_SOCKET,socket.SO_REUSE ...