@Test public void testGetField() { assertTrue(FieldUtils.getField(FieldUtilsTest.class, "test1") != null); assertTrue(FieldUtils.getField(FieldUtilsTest.class, "test2") != null); assertTrue(FieldUtils.getField(FieldUtilsTest.class, "testx") == null); }
public static Field getField(final Class<?> klass, String fieldName) { for (Class<?> target = klass; target != Object.class; target = target.getSuperclass()) { for (Field field : target.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } } return null; }
FieldUtils { public static Field getField(final Class<?> klass, String fieldName) { for (Class<?> target = klass; target != Object.class; target = target.getSuperclass()) { for (Field field : target.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } } return null; } }
FieldUtils { public static Field getField(final Class<?> klass, String fieldName) { for (Class<?> target = klass; target != Object.class; target = target.getSuperclass()) { for (Field field : target.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } } return null; }  }
FieldUtils { public static Field getField(final Class<?> klass, String fieldName) { for (Class<?> target = klass; target != Object.class; target = target.getSuperclass()) { for (Field field : target.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } } return null; }  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 Field getField(final Class<?> klass, String fieldName) { for (Class<?> target = klass; target != Object.class; target = target.getSuperclass()) { for (Field field : target.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } } return null; }  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);  }