@Test public void testWriteFieldObjectStringObject() { FieldUtilsTest test = new FieldUtilsTest(); FieldUtils.writeField(test, "test1", 1); assertTrue(test.test1 == 1); FieldUtils.writeField(test, "test2", 2); assertTrue(test.getTest2() == 2); }
public static void writeField(final Object target, final Field field, final Object value) { if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法注入.", e); } }
FieldUtils { public static void writeField(final Object target, final Field field, final Object value) { if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法注入.", e); } } }
FieldUtils { public static void writeField(final Object target, final Field field, final Object value) { if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法注入.", e); } }  }
FieldUtils { public static void writeField(final Object target, final Field field, final Object value) { if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法注入.", e); } }  static void writeField(final Object target, final Field field, final Object value); static void writeField(final Object target, final String fieldName, final Object value); static Object readField(final Object target, final Field field); static Field getField(final Class<?> klass, String fieldName); static List<Field> getAllField(final Class<?> klass); static String genGetMethodName(Field field); static String genSetMethodName(Field field); static Field[] scanAllField(final Class<?> klass, List<Class<? extends Annotation>> annotations); static void injectionStaticField(Map<String, T> templates, Class<?> target, Function<T, String> fun); }
FieldUtils { public static void writeField(final Object target, final Field field, final Object value) { if (!field.isAccessible()) { field.setAccessible(true); } try { field.set(target, value); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法注入.", e); } }  static void writeField(final Object target, final Field field, final Object value); static void writeField(final Object target, final String fieldName, final Object value); static Object readField(final Object target, final Field field); static Field getField(final Class<?> klass, String fieldName); static List<Field> getAllField(final Class<?> klass); static String genGetMethodName(Field field); static String genSetMethodName(Field field); static Field[] scanAllField(final Class<?> klass, List<Class<? extends Annotation>> annotations); static void injectionStaticField(Map<String, T> templates, Class<?> target, Function<T, String> fun);  }