2014-03-31 38 views
1

我有3個屬性的註釋:使用以前標註的屬性Java:如何將默認值設置爲使用其他註釋作爲其屬性的註釋?

public @interface Date { 
    int day() default 1; 
    int month() default 1; 
    int year() default 2000; 
} 

和註釋:

public @interface Author { 
    String name(); 
    Date date(); //default value here 
} 

如何爲屬性date設置默認值?

+0

爲什麼你想使用註釋作爲一個字段?註釋的整個想法是元數據,而不是數據。您能否分享將您引向此設計的要求? – eitanfar

+0

難道你不能只是做一個簡單的'日期日期()默認@Date();'? – Gladhus

回答

4

您提供一個默認的annotaion做到這一點...

例如:

public @interface Author { 
    String name(); 
    Date date() default @Date(year=2014); 
} 
+0

謝謝。我甚至沒有想到這種變體。 – Dragon