Java 注释,属性值必须是常量
Java annotation, Attribute value must be constant
我在 Java 中看到当我对这样的方法使用注释时是不可能的。它给出“属性必须是常量”
private static final String CONSTANT = MyClass.class.getCanonicalName();
@Timed(CONSTANT) //Attribute value must be constant
@CircuitBreaker(name = CONSTANT) //Attribute value must be constant
public String something( String something ) {
为了强调,我在这里使用@Timed 和@CircuitBreaker 作为示例。许多其他注释会产生完全相同的问题。
如何在Java中完成?我的意思是,我不想像这样硬编码这里的值。
@Timed("MyClass") @CircuitBreaker(name = "MyClass")
private static final String CONSTANT = MyClass.class.getCanonicalName();
这些是修饰符:private static final
这是data-type/object-type:String
这是您的 constant/variable/object 的名字:CONSTANT
这是发起人:=
这是属性:MyClass.class.getCanonicalName();
您的属性不是常量,因此您无法启动您的常量CONSTANT
。
我在 Java 中看到当我对这样的方法使用注释时是不可能的。它给出“属性必须是常量”
private static final String CONSTANT = MyClass.class.getCanonicalName();
@Timed(CONSTANT) //Attribute value must be constant
@CircuitBreaker(name = CONSTANT) //Attribute value must be constant
public String something( String something ) {
为了强调,我在这里使用@Timed 和@CircuitBreaker 作为示例。许多其他注释会产生完全相同的问题。
如何在Java中完成?我的意思是,我不想像这样硬编码这里的值。
@Timed("MyClass") @CircuitBreaker(name = "MyClass")
private static final String CONSTANT = MyClass.class.getCanonicalName();
这些是修饰符:private static final
这是data-type/object-type:String
这是您的 constant/variable/object 的名字:CONSTANT
这是发起人:=
这是属性:MyClass.class.getCanonicalName();
您的属性不是常量,因此您无法启动您的常量CONSTANT
。