Your AnnotatedClass
should have the fields annotated with @TestAnnotation
. Your code will return 2 then.
public class AnnotatedClass {
@TestAnnotation
public int annotatedField1 = 123;
@TestAnnotation
public String annotatedField2 = "roar";
}
Now, to query fields and methods, you need to specify the scanner while creating a Reflections
object. Moreover, the usage of Reflections
should be:
Reflections ref = new Reflections("<specify package name here>", new FieldAnnotationsScanner());