Well, there is a way, but he needs takeWhileit to be in jdk-9.
I am doing a mapping here to get the field names. You need to add a method @SuppressWarnings("null").
System.out.println(Stream.iterate(this.getClass(), (Class<?> x) -> x.getSuperclass())
.takeWhile(x -> x != null)
.flatMap(c -> Arrays.stream(c.getDeclaredFields()))
.map(c -> c.getName())
.collect(Collectors.toList()));
jdk-9 Stream.iterate, Iterator seed, hasNext, next, .
StreamEx btw:
StreamEx.of(Stream.iterate(this.getClass(), (Class<?> x) -> x.getSuperclass()))
.takeWhile(x -> x != null)
.flatMap(c -> Arrays.stream(c.getDeclaredFields()))
.map(c -> c.getName())
.collect(Collectors.toList());
:
Stream.iterate(this.getClass(), c -> c != null, (Class<?> c) -> c.getSuperclass())
.flatMap(c -> Arrays.stream(c.getDeclaredFields()))
.map(c -> c.getName())
.collect(Collectors.toList())