用途
Optional.map:
instanceObj.final_doc_type = Optional.ofNullable(instance) .map(Instance::getFinaldocument) .map(document::getValue) .map(Value::getType) .map(Type::getValue) .orElse(null);
这设置
final_doc_type为
null链中是否有任何东西
null。
如果只想在非空值的情况下设置其值,请删除分配,并将其更改
orElse为
ifPresent:
Optional.ofNullable(instance) .ifPresent(t -> instanceObj.final_doc_type = t);



