加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

哪些是Java注释中字段和方法的默认修饰符?

发布时间:2020-12-15 00:40:51 所属栏目:Java 来源:网络整理
导读:哪个是x和m的默认修饰符 public @interface Anno { int m() default x; int x = 10;} ? 我想上面的代码相当于: public @interface Anno { public int m() default x; public static final int x = 10;} 修饰符public和public static final是多余的,但我没
哪个是x和m的默认修饰符
public @interface Anno {
    int m() default x;
    int x = 10;
}

我想上面的代码相当于:

public @interface Anno {
    public int m() default x;
    public static final int x = 10;
}

修饰符public和public static final是多余的,但我没有找到官方解释.

我在这看:
https://docs.oracle.com/javase/8/docs/technotes/guides/language/annotations.html
https://docs.oracle.com/javase/tutorial/java/annotations/index.html
http://www.vogella.com/tutorials/JavaAnnotations/article.html

是否有关于这些修饰符的文档?或者有人可以提供“正式”解释吗?

解决方法

是的,我相信你是对的 – 我发现支持这一点的一点文件是在 JLS 9.6:

Unless explicitly modified herein,all of the rules that apply to normal interface declarations apply to annotation type declarations.

所以它基本上表现得像普通的接口,其中public和abstract是冗余的,所有字段都是隐式静态和最终的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读