I made a custom Annotation for my project which will be used only with fields, that is
@MyAnnotation int myVariable
I have another class which wi
int getMyVariable(Foo foo) throws IllegalArgumentException, IllegalAccessException{ for(Field f:foo.getClass().getDeclaredFields()){ /** * Ensure the RetentionPolicy of 'MyAnnotation' is RUNTIME. */ if(f.isAnnotationPresent(MyAnnotation.class)){ return f.getInt(foo); } } return -1; }