我有一個實體自引用。我可以拼合多個深度自引用實體嗎?
public class Category {
private List<Category> children;
}
隨着給定的類別列表,我該如何將它們全部弄平?
C11
C21
C31
C32
C22
C12
我想要的
C1 C21 C31 C32 C22 C12
我嘗試了名單。
public static <T extends BaseEntity & SelfReferencing<T>> void flatten(
final T parent, final Function<T, Stream<T>> function,
final Consumer<T> consumer) {
function.apply(parent).forEach(child -> {
consumer.accept(child);
flatten(child, function, consumer);
});
}
@talex查看我的更新。 –
該函數不會返回任何只是遍歷所有元素的任何東西。 – talex