mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
IDEA-163767 Simplify optional.isPresent() inspection doesn't suggest simplify trivial case
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
return first;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
// could be replaced in Java-9 with return first.or(() -> "xyz");
|
||||
// but the only option in Java-8 is return first.map(Optional::of).orElseGet(() -> Optional.of("xyz")) which is weird
|
||||
if (first.isPr<caret>esent()) {
|
||||
return first;
|
||||
}
|
||||
return Optional.of("xyz");
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main<T> {
|
||||
Optional<Object> foo(Optional<Object> first) {
|
||||
if (first.isPr<caret>esent()) {
|
||||
return first;
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user