Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaOptional patternsSingle-choice MCQ

Why does the second line fail to compile while the first compiles?

Optional<List<Integer>> a = Optional.of(List.of(1, 2)); // line 1 below compiles, line 2 does not Stream<Integer> ok = a.stream().flatMap(List::stream); Stream<Integer> bad = a.map(List::stream);