Aha.
public ArrayList<String> getAllFields() {
return Arrays.stream(getClass().getDeclaredFields())
.filter(field -> !Modifier.isStatic(field.getModifiers()))
.map(this::getFieldValue)
.filter(Objects::nonNull)
.map(Objects::toString)
.collect(Collectors.toCollection(ArrayList::new));
}
private Object getFieldValue(final Field field) {
try {
return field.get(this);
} catch (final IllegalAccessException e) {
throw new RuntimeException(e);
}
}
Tímhle kódem bych to uzavřel. Pokud nemáte návrhy na zlepšení.
Přidání filtru na určité typy bych dal do samostatné otázky. viz odkaz výše.
Díky