+import java.util.Optional;
+ public static void main(String[] args) {
+ First notNull = new First(new Second(new Third(new Fourth("Not Null String"))));
+ First nestedNull = new First(new Second(new Third(null)));
+ System.out.println(get(notNull).orElse("is null"));
+ System.out.println(get(nestedNull).orElse("is null"));
+ String test = get(nestedNull).orElse(null);
+ System.out.println(test);
+ private static Optional<String> get(First first) {
+ return Optional.ofNullable(first.getSecond())
+ .map(Fourth::getString);