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
  • 5,657
  • 3
  • 35
  • 55
Nithish Thomas
  • 1,365
  • 13
  • 19

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,714
  • 1
  • 25
  • 35