package com.whn.hellospring.utils; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collector; public class MyOptional { public static List toList(Optional option) { return option. map(Collections::singletonList). orElse(Collections.emptyList()); } public static R collect(Optional option, Collector collector) { final A container = collector.supplier().get(); option.ifPresent(v -> collector.accumulator().accept(container, v)); return collector.finisher().apply(container); } }