Prechádzať zdrojové kódy

上传文件至 'src/main/java/com/weavi/ahh_v2/utils'

rookies 5 rokov pred
rodič
commit
b6a99f5db6

+ 18 - 0
src/main/java/com/weavi/ahh_v2/utils/Optional2List.java

@@ -0,0 +1,18 @@
+package com.weavi.ahh_v2.utils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * @auther jiangzuole
+ * @date 2019-05-28
+ * @time 10:39
+ */
+public class Optional2List {
+    public static <T> List<T> toList(Optional<T> option) {
+        return option.
+                map(Collections::singletonList).
+                orElse(Collections.emptyList());
+    }
+}