I'd like to get an Optional value, I have something like this:
Optional<String> value =
Optional.ofNullable(MyObject.getPeople())
.ifPresent(people -> people
.stream()
.filter(person -> person.getName().equals("test1"))
.findFirst()
.map(person -> person.getId()));
person.getId() should return a string, I tried this but it didn't work, getting incompatible types: void cannot be converted to java.util.Optional
Optional<String> value =
Optional.ofNullable(MyObject.getPeople())
.ifPresent(people -> people
.stream()
.filter(person -> person.getName().equals("test1"))
.findFirst()
.map(person -> person.getId()))
.orElse(null);
Any idea? Thanks