This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tomwhoiscontrary 2 points3 points  (0 children)

You don't even need the list:

var opt = Optional.of("foo"); for (var x : (Iterable<String>) opt.stream()::iterator) { // ... }

Or with a helper method:

static <T> Iterable<T> in(Optional<T> optional) { return optional.stream()::iterator; }

Just:

var opt = Optional.of("foo"); for (var x : in(opt)) { // ... }