@Test public void testReadField() { FieldUtilsTest test = new FieldUtilsTest(); assertTrue(FieldUtils.readField(test, FieldUtils.getField(FieldUtilsTest.class, "test1")).equals(0)); }
public static Object readField(final Object target, final Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { return field.get(target); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法读取.", e); } }
FieldUtils { public static Object readField(final Object target, final Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { return field.get(target); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法读取.", e); } } }
FieldUtils { public static Object readField(final Object target, final Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { return field.get(target); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ServerBootstrapException(target.getClass() + " 的 " + field.getName() + " 属性无法读取.", e); } }  }
FieldUtils { public static Object readField(final Object target, final Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { return field.get(target); } 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 Object readField(final Object target, final Field field) { if (!field.isAccessible()) { field.setAccessible(true); } try { return field.get(target); } 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);  }