Reputation: 37058
A few days ago I was forced to use the following construction for my class declaration:
@Table(name="UserPattern", uniqueConstraints={
@UniqueConstraint(columnNames={"user_id", "patern_id"})
})
I was very surprised by this syntax.
Usually I thought that if I should to pass array to annotation O I should write the following:
declared_inside_annotation_name={value1,value2...}
but in this case it looks like the following:
uniqueConstraints={
@UniqueConstraint(columnNames={"user_id", "patern_id"})
}
@Table
annotation declaration:
@Target(TYPE)
@Retention(RUNTIME)
public @interface Table {
String name() default "";
String catalog() default "";
String schema() default "";
UniqueConstraint[] uniqueConstraints() default { };
Index[] indexes() default {};
}
please clarify this syntax.
Upvotes: 0
Views: 979
Reputation: 3059
There is actually not a conflict between your expected syntax from your declared_inside_annotation_name
example and the syntax from the @Table
annotation. The type of elements for an array property of an annotation does not necessarily have to be a string (which might be what you have expected). It may actually be another annotation.
This is the case with the uniqueConstraints
property of the @Table
annotation. If you check the declaration of the UniqueConstraint
class, you see that it is an annotation itself. When writing it down, you use the usual @AnnotationTypeName
notation.
Upvotes: 1