Results 1 to 1 of 1
Thread: Annotating enum constants
- 01-17-2012, 10:54 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 1
- Rep Power
- 0
Annotating enum constants
Hi, thanks for reading this post.
I expect the following code to indicate that the enum constant TRUE is annotated with the annotation @Annotated, but it does not. Does anyone see what's wrong? Thanks in advance,
Dan.Java Code:import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; public enum EnumAnnotationTest { FALSE, @Annotated TRUE; private EnumAnnotationTest() { System.out.println("Enum: "+ this.name() +", annotated? "+ this.getClass().isAnnotationPresent(Annotated.class)); } public static void main(String[] args){} } @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface Annotated{}
Similar Threads
-
public static enum vs enum class
By Dipke in forum New To JavaReplies: 3Last Post: 08-30-2011, 10:45 AM -
Enumerated constants
By ohbugger in forum Advanced JavaReplies: 10Last Post: 01-29-2011, 01:50 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks