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 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 {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.