Designing interface for hierarchical entity
问题 I have to design an interface for hierarchical entity: interface HierarchicalEntity<T extends HierarchicalEntity<T>> { T getParent(); Stream<T> getAncestors(); } It's quite easy to implement default getAncestors() method in terms of getParent() in such a way that the former would return Stream of all the ancestors. Implementation example: default Stream<T> getAncestors() { Stream.Builder<T> parentsBuilder = Stream.builder(); T parent = getParent(); while (parent != null) { parentsBuilder.add