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

前端之家收集整理的这篇文章主要介绍了哪些是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是多余的,但我没有找到官方解释.

我在这看:
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

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

解决方法@H_502_21@
是的,我相信你是对的 – 我发现支持这一点的一点文件是在 JLS 9.6

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

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

原文链接:https://www.f2er.com/java/129446.html

猜你在找的Java相关文章