2016-07-23 13 views
-1

我正在尋找一種方法來將註釋中的變量的默認值設置爲相同註釋中的另一個變量,這裏是我想要的要做到:如何將變量的默認值設置爲相同註釋中的另一個

public @interface Command { 
    String commandName(); 
    String triggerName() default commandName(); 
    String description() default ""; 
} 

通過這樣做,我得到與Eclipse的錯誤,那就是:

The value for annotation attribute Command.triggerName must be a constant expression 

所以我不能完全肯定不懂,也許它要求我改變「commandName」給一個常量變量(帶final),但是我只能把public和abstract。

有沒有辦法做我在解釋什麼?

回答

0

你不能那樣做,因爲按照指示,默認值必須是編譯時常量。最接近你可以做的是what Spring 4.3 does,在讀者代碼中實現邏輯(如註釋處理器或運行時反射)並記錄它。

相關問題