What is the difference between public and abstract modifier for an elements of annotation in Java.
For example we coul
Both of them are redundant. As described in the JLS the methods of an interface are abstract and public by default.
There is no impact - it's just a redundant declaration. Same with interface's methods, for instance.
In java annotation is a special type of interface. So it follows rules of interface and interface methods are by default public
and abstract
. In spite of default consideration, you could still add both public
and abstract
modifier explicitly. But it will be considered as redundant.
Additionally if you declare a variable inside annotation, by default it will be a final
and static
variable.
Every interface
is implicitly abstract
. The interface implicitly declares a public abstract
member method.
An annotation type is a special kind of interface. In an interface, all methods are implicitly both public and abstract, but is allowed to explicitly state that a method is public and/or abstract. Declaring an interface method as public or abstract has no effect, however.