E
Emmeran Seehuber
Hi,
is it possible to annotate members of enums? It doesn't seem so -- at least
I can't get the values at runtime
This is my annotation class:
@Retention(RetentionPolicy.RUNTIME)
public @interface BCComment {
String value();
}
And this is the class containing the enum:
public class ByteCodeCommands {
public enum ByteCode {
@BCComment("Anfang einer Methode")
METHODPROLOG,
@BCComment("Focus auf die Instance-Variablen")
FOCUSSELFVARIABLES,
// ...
}
public static void main(String[] args) throws IOException {
// ...
for (ByteCode code : ByteCode.values()) {
Annotation[] annotations = ByteCode.class.getAnnotations();
Annotation[] annos = code.getClass().getAnnotations();
System.out.println(annotations.length);
System.out.println(annos.length);
BCComment comment = code.getClass().getAnnotation(BCComment.class);
System.out.println(comment);
}
// ...
}
}
When running this program it prints:
0
0
null
What is wrong with my code? Is it not possible to annotate enum members?
Thanks.
cu,
Emmy
is it possible to annotate members of enums? It doesn't seem so -- at least
I can't get the values at runtime
This is my annotation class:
@Retention(RetentionPolicy.RUNTIME)
public @interface BCComment {
String value();
}
And this is the class containing the enum:
public class ByteCodeCommands {
public enum ByteCode {
@BCComment("Anfang einer Methode")
METHODPROLOG,
@BCComment("Focus auf die Instance-Variablen")
FOCUSSELFVARIABLES,
// ...
}
public static void main(String[] args) throws IOException {
// ...
for (ByteCode code : ByteCode.values()) {
Annotation[] annotations = ByteCode.class.getAnnotations();
Annotation[] annos = code.getClass().getAnnotations();
System.out.println(annotations.length);
System.out.println(annos.length);
BCComment comment = code.getClass().getAnnotation(BCComment.class);
System.out.println(comment);
}
// ...
}
}
When running this program it prints:
0
0
null
What is wrong with my code? Is it not possible to annotate enum members?
Thanks.
cu,
Emmy