What are the default modifiers for fields and methods in Java annotations?

Which is the default modifier for X and M

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

I think the above code is equivalent to:

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

The modifiers public and public static final are redundant, but I have not found an official explanation

I'm here to see: 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

Is there documentation on these modifiers? Or can someone provide a "formal" explanation?

Solution

Yes, I'm sure you're right – I found that one of the documents supporting this is in JLS 9.6:

Therefore, it basically behaves like an ordinary interface, in which public and abstract are redundant, and all fields are implicitly static and final

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>