ReflectionUtils { @SuppressWarnings("unchecked") public static <R, T> Collection<R> getFieldValues(Class<T> clazz, Class<R> type, @Nullable T instance) { Collection<Field> fields = Arrays.stream(clazz.getDeclaredFields()) .filter(field -> field.getType() == type) .filter(field -> instance != null || Modifier.isStatic(field.getModifiers())) .collect(Collectors.toList()); Collection<R> values = new ArrayList<>(fields.size()); try { for (Field field : fields) { field.setAccessible(true); values.add((R) field.get(instance)); } } catch (IllegalAccessException e) { throw new RuntimeException("Cannot access field", e); } return values; } private  ReflectionUtils(); static Collection<E> getByModifier(E[] executables, int modifier); static Option<Method> getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes); static List<Method> getMethods(Class<?> clazz, String methodName); static Set<Method> getMethodsAnnotatedWith(Class<?> clazz, Class<? extends Annotation> annotation); static Collection<T> getStaticFieldValues(Class<?> clazz, Class<T> type); @SuppressWarnings("unchecked") static Collection<R> getFieldValues(Class<T> clazz, Class<R> type, @Nullable T instance);  }
@Test void getFieldValues() { Collection<String> values = ReflectionUtils.getFieldValues(Bar.class, String.class, new Bar()); Assertions.assertEquals(1, values.size()); Assertions.assertEquals("value", values.iterator().next()); }