0

How can I make my frameworks MyAnnotation have a user-defined enum type as the parameter?

Like @MyAnnotation(Colors.BLUE). Another, less idea solution would be @MyAnnotation(Colors.BLUE.getName()).

Edit: as in the enum is user-specified. I tried Enum<?> value(), but that didn't work

  • You're allowed to use constants as parameters. See https://stackoverflow.com/questions/1458535/which-types-can-be-used-for-java-annotation-members – user Jul 08 '20 at 22:37

1 Answers1

0

You can supply your enum element explicitly when defining the annotation for the relevant type.

enum MyEnum {
    MY_ELEMENT
}
@interface MyAnnotation {

    MyEnum value();

}
@MyAnnotation(value = MyEnum.MY_ELEMENT)
class MyClass {
    
}
Jason
  • 5,154
  • 2
  • 12
  • 22
  • but the enum should be user-defined, so the annotation should not know about MyEnum –  Jul 09 '20 at 06:24