Java8新特性之重复注解(repeating annotations)浅析
一、什么是重复注解
允许在同一申明类型(类,属性,或方法)的多次使用同一个注解
二、一个简单的例子
java8之前也有重复使用注解的解决方案,但可读性不是很好,比如下面的代码:
public@interfaceAuthority{ Stringrole(); }
public@interfaceAuthorities{ Authority[]value(); }
publicclassRepeatAnnotationUseOldVersion{ @Authorities({@Authority(role="Admin"),@Authority(role="Manager")}) publicvoiddoSomeThing(){ } }