1

I am trying to write something similar to

@Property(name="className",value=MyClazz.class.getName())
class MyClazz{
}

But the compiler complains :

The value for annotation attribute Property.value must be a constant expression

Is there a workaround for this? or should i just hard-code the class name.

lrkwz
  • 6,105
  • 3
  • 36
  • 59
Nithish Thomas
  • 1,515
  • 14
  • 20

1 Answers1

2

Using the Class value type instead of String will support the following usage:

@MyQualifier(String.class)
String myMethod() {
    return "hello";
}

Your annotation type would be:

...
@Retention(RUNTIME)
public @interface MyQualifier {
    Class value();
}
Kenston Choi
  • 2,862
  • 1
  • 27
  • 37