vancetang / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

reflections.getTypesAnnotatedWith(...) finds class, but getAnnotations().length is 0 #134

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
in 0.9.8 I can correctly find classes decorated with an annotation:

Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(CommandName.class);

but when I try to see how many annotations are on each class I always see zero:

for(Class c : annotated)
{
     int numAnnotations = c.getAnnotations().length;
}

Why does c.getAnnotations() return an array of length 0?

Original issue reported on code.google.com by rmbarn...@gmail.com on 13 Nov 2012 at 8:15

GoogleCodeExporter commented 9 years ago
Is becouse you don't set the correct Rentention on your Annotation:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Section {
    String id();
    Action[] actions() default {};
}

http://tutorials.jenkov.com/java-reflection/annotations.html

Original comment by fernando...@gmail.com on 6 May 2013 at 9:24

GoogleCodeExporter commented 9 years ago

Original comment by ronm...@gmail.com on 23 Nov 2013 at 12:26