Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default properties of Java Annotation

What are the exact default values of two meta annotations (Target and Retention) in a user defined annotation?

public @interface AnnotationWithDefaultProps {
}
like image 223
Abidi Avatar asked Feb 15 '11 22:02

Abidi


People also ask

What is @interface annotation in Java?

@interface is used to create your own (custom) Java annotations. Annotations are defined in their own file, just like a Java class or interface. Here is custom Java annotation example: @interface MyAnnotation { String value(); String name(); int age(); String[] newNames(); }

What is @property annotation in Java?

The @Property annotation is used to denote a Java class field, a setter method, or a constructor parameter that is used to inject an SCA property value.

What is the use of @interface annotation?

The @interface element is used to declare an annotation. For example: @interface MyAnnotation{}


1 Answers

According to the source code, none of them has a default value, which means you must provide it, whenever you use the annotation. The meaning of the missing annotation is defined in the javadoc:

For Target it means

If a Target meta-annotation is not present on an annotation type declaration, the declared type may be used on any program element.

and for Retention it means

If no Retention annotation is present on an annotation type declaration, the retention policy defaults to RetentionPolicy.CLASS.

like image 74
maaartinus Avatar answered Oct 14 '22 23:10

maaartinus