@Test void getAllFields() { Collection<Field> fields = ReflectionUtils.getAllFields(TestFieldClass.class); assertEquals(2, fields.size()); }
public static Collection<Field> getAllFields(Class<?> clazz) { Map<String, Field> fields = new LinkedHashMap<>(); Class<?> targetClass = clazz; while (targetClass != null) { Field[] targetClassFields; try { targetClassFields = targetClass.getDeclaredFields(); } catch (NoClassDefFoundError e) { throw new NoClassDefFoundError("Failed to get fields for class [" + targetClass.getName() + "] because the class [" + e.getMessage() + "] couldn't be found in the ClassLoader."); } for (Field field : targetClassFields) { if (!field.isSynthetic() && !fields.containsKey(field.getName())) { fields.put(field.getName(), field); } } targetClass = targetClass.getSuperclass(); } return fields.values(); }
ReflectionUtils { public static Collection<Field> getAllFields(Class<?> clazz) { Map<String, Field> fields = new LinkedHashMap<>(); Class<?> targetClass = clazz; while (targetClass != null) { Field[] targetClassFields; try { targetClassFields = targetClass.getDeclaredFields(); } catch (NoClassDefFoundError e) { throw new NoClassDefFoundError("Failed to get fields for class [" + targetClass.getName() + "] because the class [" + e.getMessage() + "] couldn't be found in the ClassLoader."); } for (Field field : targetClassFields) { if (!field.isSynthetic() && !fields.containsKey(field.getName())) { fields.put(field.getName(), field); } } targetClass = targetClass.getSuperclass(); } return fields.values(); } }
ReflectionUtils { public static Collection<Field> getAllFields(Class<?> clazz) { Map<String, Field> fields = new LinkedHashMap<>(); Class<?> targetClass = clazz; while (targetClass != null) { Field[] targetClassFields; try { targetClassFields = targetClass.getDeclaredFields(); } catch (NoClassDefFoundError e) { throw new NoClassDefFoundError("Failed to get fields for class [" + targetClass.getName() + "] because the class [" + e.getMessage() + "] couldn't be found in the ClassLoader."); } for (Field field : targetClassFields) { if (!field.isSynthetic() && !fields.containsKey(field.getName())) { fields.put(field.getName(), field); } } targetClass = targetClass.getSuperclass(); } return fields.values(); } private  ReflectionUtils(); }
ReflectionUtils { public static Collection<Field> getAllFields(Class<?> clazz) { Map<String, Field> fields = new LinkedHashMap<>(); Class<?> targetClass = clazz; while (targetClass != null) { Field[] targetClassFields; try { targetClassFields = targetClass.getDeclaredFields(); } catch (NoClassDefFoundError e) { throw new NoClassDefFoundError("Failed to get fields for class [" + targetClass.getName() + "] because the class [" + e.getMessage() + "] couldn't be found in the ClassLoader."); } for (Field field : targetClassFields) { if (!field.isSynthetic() && !fields.containsKey(field.getName())) { fields.put(field.getName(), field); } } targetClass = targetClass.getSuperclass(); } return fields.values(); } private  ReflectionUtils(); static Collection<Field> getAllFields(Class<?> clazz); static Field getField(Class<?> clazz, String fieldName); static Class getTypeClass(Type type); static void setFieldValue(Object instanceContainingField, String fieldName, Object fieldValue); static Class<?> getLastGenericFieldType(Field field); static Type getLastFieldGenericArgument(Field field); static Type getLastTypeGenericArgument(Type type); static Class<?> getLastGenericClassType(Class clazz, Class filterClass); static Type getGenericClassType(Class clazz, Class filterClass); static Type[] resolveSuperArguments(Type[] parameters, Type childType); static Type[] resolveSuperArguments(Type[] parameters, Class childClass, Type[] childParameters); static Type resolveType(Type type, Map<TypeVariable, Type> typeMapping); static Type resolveType(Type targetType, Type rootType); static Type unserializeType(String serializedType, ClassLoader classLoader); static T getDirectAnnotation(Class<T> annotationClass, AnnotatedElement element); static List<Type> getDirectTypes(Type type); @Unstable static String serializeType(Type type); @Unstable static Collection<Method> getAllMethods(Class<?> clazz); }
ReflectionUtils { public static Collection<Field> getAllFields(Class<?> clazz) { Map<String, Field> fields = new LinkedHashMap<>(); Class<?> targetClass = clazz; while (targetClass != null) { Field[] targetClassFields; try { targetClassFields = targetClass.getDeclaredFields(); } catch (NoClassDefFoundError e) { throw new NoClassDefFoundError("Failed to get fields for class [" + targetClass.getName() + "] because the class [" + e.getMessage() + "] couldn't be found in the ClassLoader."); } for (Field field : targetClassFields) { if (!field.isSynthetic() && !fields.containsKey(field.getName())) { fields.put(field.getName(), field); } } targetClass = targetClass.getSuperclass(); } return fields.values(); } private  ReflectionUtils(); static Collection<Field> getAllFields(Class<?> clazz); static Field getField(Class<?> clazz, String fieldName); static Class getTypeClass(Type type); static void setFieldValue(Object instanceContainingField, String fieldName, Object fieldValue); static Class<?> getLastGenericFieldType(Field field); static Type getLastFieldGenericArgument(Field field); static Type getLastTypeGenericArgument(Type type); static Class<?> getLastGenericClassType(Class clazz, Class filterClass); static Type getGenericClassType(Class clazz, Class filterClass); static Type[] resolveSuperArguments(Type[] parameters, Type childType); static Type[] resolveSuperArguments(Type[] parameters, Class childClass, Type[] childParameters); static Type resolveType(Type type, Map<TypeVariable, Type> typeMapping); static Type resolveType(Type targetType, Type rootType); static Type unserializeType(String serializedType, ClassLoader classLoader); static T getDirectAnnotation(Class<T> annotationClass, AnnotatedElement element); static List<Type> getDirectTypes(Type type); @Unstable static String serializeType(Type type); @Unstable static Collection<Method> getAllMethods(Class<?> clazz);  }