void (Optional<String> opt) { X x = (methodReferenceConstantValue, s1) -> false; Boolean aBoolean = opt.map(s -> false) .map(o1 -> true) .map(o -> false) .orElse(new Random().nextBoolean()); if (opt.isPresent()) { Stream.generate(() -> true) .limit(10) .forEach(System.out::println); } }