ctubbsii commented on a change in pull request #2524:
URL: https://github.com/apache/thrift/pull/2524#discussion_r818286243
##########
File path: lib/java/src/org/apache/thrift/Option.java
##########
@@ -54,6 +56,19 @@ public T or(T other) {
return other;
}
}
+
+ /**
+ * Turn this Option into Java 8 Optional type
+ * @return Java 8+ Optional Type
+ */
+ public Optional<T> toOptional() {
+ if (isDefined()) {
+ return Optional.of(get());
+ } else {
+ return Optional.empty();
+ }
Review comment:
Could also do:
```suggestion
return Optional.ofNullable(isDefined() ? get() : null);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]