class User {
private String name;
private User1 user1;
}
class User1 {
private String name;
private User2 user2;
}
class User2 {
private String name;
private User3 user3;
}
class User3 {
private String name;
}
使用方式:
解决思路:
Optional类中提供了 map 方法, 可以顺利承载Null传入参数或者输出Null返回参数, 返回类型为Optional
public<U> Optional<U> map(Function<? super T, ? extends U> mapper) {
Objects.requireNonNull(mapper);
if (!isPresent())
return empty();
else {
return Optional.ofNullable(mapper.apply(value));
}
}