Sunday, 29 June 2014

@Repeatable

@Repeatable annotation, introduced in Java SE 8, indicates that the marked annotation can be applied more than once to the same declaration or type use.

It is much helpful when you have multiple fields declared in an annotation. For example:

@Repeatable
public @interface Role {
   String type;
   String[] allowed;
}

In this case, it is much easier to use this kind of annotation for multiple roles:

@Role(type="readonly", allowed={"view"})
@Role(type="admin", allowed={"view,add,update,delete"})
public boolean checkAllowed() {
}




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment