@Test public void testCreateAndCallSetter() throws Throwable { Map<String, ReflectionUtil.PropertyAccessor<?>> propertyAccessors = ReflectionUtil.getPropertyAccessors(TestBean.class); TestBean bean = new TestBean(); assertThat(bean.getValue(), is(nullValue())); assertThat(propertyAccessors.get("value").handle().type().parameterType(1), equalTo(String.class)); assertThat(propertyAccessors.get("init").handle().type().parameterType(1), equalTo(String.class)); propertyAccessors.get("value").handle() .invoke(bean, "val1"); assertThat(bean.getValue(), is("val1")); propertyAccessors.get("init").handle() .invoke(bean, "val2"); assertThat(bean.getInit(), is("val2")); }
static <T> Map<String, PropertyAccessor<?>> getPropertyAccessors(Class<T> type) { Set<String> transientProps = new HashSet<>(); Map<String, PropertyAccessor<?>> propertyAccessors = new HashMap<>(); initMethods(type, transientProps, propertyAccessors); initFields(type, transientProps, propertyAccessors); return propertyAccessors; }
ReflectionUtil { static <T> Map<String, PropertyAccessor<?>> getPropertyAccessors(Class<T> type) { Set<String> transientProps = new HashSet<>(); Map<String, PropertyAccessor<?>> propertyAccessors = new HashMap<>(); initMethods(type, transientProps, propertyAccessors); initFields(type, transientProps, propertyAccessors); return propertyAccessors; } }
ReflectionUtil { static <T> Map<String, PropertyAccessor<?>> getPropertyAccessors(Class<T> type) { Set<String> transientProps = new HashSet<>(); Map<String, PropertyAccessor<?>> propertyAccessors = new HashMap<>(); initMethods(type, transientProps, propertyAccessors); initFields(type, transientProps, propertyAccessors); return propertyAccessors; } private  ReflectionUtil(); }
ReflectionUtil { static <T> Map<String, PropertyAccessor<?>> getPropertyAccessors(Class<T> type) { Set<String> transientProps = new HashSet<>(); Map<String, PropertyAccessor<?>> propertyAccessors = new HashMap<>(); initMethods(type, transientProps, propertyAccessors); initFields(type, transientProps, propertyAccessors); return propertyAccessors; } private  ReflectionUtil();  }
ReflectionUtil { static <T> Map<String, PropertyAccessor<?>> getPropertyAccessors(Class<T> type) { Set<String> transientProps = new HashSet<>(); Map<String, PropertyAccessor<?>> propertyAccessors = new HashMap<>(); initMethods(type, transientProps, propertyAccessors); initFields(type, transientProps, propertyAccessors); return propertyAccessors; } private  ReflectionUtil();   }