Which are the default modifiers for x
and m
in
public @interface Anno {
int m() default x;
int x = 10;
}
?
I suppose that the code above is equivalent to:
public @interface Anno {
public int m() default x;
public static final int x = 10;
}
where the modifiers public
and public static final
are redundant, but I didn't find an official explanation for this.
I was looking here: 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 any documentation regarding those modifiers? Or could someone provide a "formal" explanation?
Yes, I believe you're right - and the one bit of documentation I've found to support this is in JLS 9.6:
Unless explicitly modified herein, all of the rules that apply to normal interface declarations apply to annotation type declarations.
So it's basically behaving like a normal interface, where public
and abstract
are redundant and all fields are implicitly static and final.
See more on this question at Stackoverflow