1
0

[MINOR] NPE Optimization for Option (#2158)

This commit is contained in:
dugenkui
2020-10-12 08:55:41 +08:00
committed by GitHub
parent d4d4c8c899
commit 032bc3b08f

View File

@@ -98,6 +98,9 @@ public final class Option<T> implements Serializable {
}
public <U> Option<U> map(Function<? super T, ? extends U> mapper) {
if (null == mapper) {
throw new NullPointerException("mapper should not be null");
}
if (!isPresent()) {
return empty();
} else {
@@ -140,6 +143,8 @@ public final class Option<T> implements Serializable {
@Override
public String toString() {
return "Option{val=" + val + '}';
return val != null
? "Option{val=" + val + "}"
: "Optional.empty";
}
}