You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by GitBox <gi...@apache.org> on 2022/03/03 03:34:24 UTC

[GitHub] [thrift] ctubbsii commented on a change in pull request #2524: THRIFT-5520 [java lib] add support for converting to java optional

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: notifications-unsubscribe@thrift.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org