I create my annotation
public @interface MyAnnotation {
}
I put it on fields in my test object
public class TestObject {
You need to mark the annotation as being available at runtime. Add the following to your annotation code.
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
}
/**
* @return null safe set
*/
public static Set<Field> findFields(Class<?> classs, Class<? extends Annotation> ann) {
Set<Field> set = new HashSet<>();
Class<?> c = classs;
while (c != null) {
for (Field field : c.getDeclaredFields()) {
if (field.isAnnotationPresent(ann)) {
set.add(field);
}
}
c = c.getSuperclass();
}
return set;
}