Is there a way to declare an annotation attribute for *any* enum?

前端 未结 3 2109
终归单人心
终归单人心 2021-02-07 04:04

At the moment I am developing an annotation-based binding-framework for Java Swing that uses JGoodies Binding under the hood. Unfortunately I am stuck with an annotation for a J

3条回答
  •  后悔当初
    2021-02-07 04:20

    It's not going to work the way you want it to. As you've found out, you can only use really plain return types in annotations. Additionally, trying to get around these restrictions by doing stuff like abusing String isn't going to work because you need to be using a constant expression for initialising your annotation's values.

    I think the closest you're going to get is to initialise with a String and then use code to compare with the enum's name(). But there goes your type safety...

提交回复
热议问题