2
如何打印不同批註的批註值?如何獲取不同批註的值
我有以下兩個註解
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Author
{
String name() default "--Unknown--";
String date() default "--Unknown--";
}
和
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Revision
{
int version() default 0;
String modifiedBy() default "--Unknown--";
}
現在一個班同時使用本註釋,這個類裏面我想顯示兩個註釋值註釋
@Author(
name = "Panther",
date = "22.04.2013"
)
@Revision(
version = 2,
modifiedBy = "Black",
)
public class AnnotationTest
{
public static void main(String[] args)
{
AnnotationTest b = new AnnotationTest();
for(Annotation a : AnnotationTest.class.getDeclaredAnnotations())
{
// for Author display name and date
// for revision display version and modifiedBy
}
}
}
有沒有辦法做到這一點?