A new year and another Java gripe! This time its annotations and the lack of anything useful by way of parameters. Implementing the Goetz annotations from Concurrency In Practice, I wanted to include an enum as a parameter type. Kind of like this
|
So far so good. I then wanted to somehow parameterise the enum constants themselves to give extra information.
|
Here’s where the trouble began.
Using the static constructor method is fine when I want to create an instance of a type but not when I want to annotate some method. For example,
|
The compiler very quickly complains that the attribute value must be constant. Specifically,
an enum annotation value must be an enum constant
To get round things, you can just create several attributes for the annotation. Rather than have a nice CLASS
type which can optionally have a description, I was forced to have one attribute of type and another to capture the additional information.
|
Shame on you Java! I’d love to know more about why things are like this, so if you can help, please post a comment.