I'm experimenting with annotations, and reflection in Java. This simple piece of code below, I would of thought would work. What I'm I doing wrong.
Code:
@interface Tag {}
@Tag
public class Main {
public static boolean isTagged(Object o) {
return o.getClass().isAnnotationPresent(Tag.class);
}
public static void main(String[] args) {
System.out.println(isTagged(new Main()));
}
}
I've greated an annotation call Tag applied it to the class Main, then written a function to check if the Tag annotation is present (isTagged). I'd expect to see true printed to STDOUT. But I'm getting "false". I'm sure this has to be somthing simple.
Any help greatfully recieved. Thanks
Bookmarks