AnnotationInjector { public static void inject(final Object object, final Factory factory) { if (object == null) { throw new IllegalArgumentException("object cannot be null."); } if (factory == null) { throw new IllegalArgumentException("factory cannot be null."); } Class<?> c = object.getClass(); for (final Method method : c.getMethods()) { if (method.isAnnotationPresent(InjectForRequest.class)) { injectIntoMethod(object, factory, method); } } while (c != Object.class && c != null) { for (final Field field : c.getDeclaredFields()) { if (field.isAnnotationPresent(InjectForRequest.class)) { injectIntoField(object, factory, field); } } c = c.getSuperclass(); } }  static void inject(final Object object, final Factory factory); static Field[] findFieldsWithAnnotation(final Object object,
                                                   final Class<? extends Annotation> annnotationClass);  }
@Test public void testInject() { final Factory f = new Factory() { @SuppressWarnings("unchecked") public <T> T getObject(final String name, final Class<T> type) { return (T) name; } }; final Sample object = new Sample(); AnnotationInjector.inject(object, f); assertEquals("me", object.foo); assertEquals("foot", object.foot); }