mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
OptionalIsPresentInspection: warn if map(x -> nullable).orElse(null)
In this case semantics preserved if map expression returns null.
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Main {
|
||||
|
||||
public void test(Optional<String> opt, Function<String, Object> onPresent, Supplier<Object> onEmpty) {
|
||||
// warning level: no semantics change
|
||||
Object o = opt.map(onPresent::apply).orElse(null);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace Optional.isPresent() condition with functional style expression" "GENERIC_ERROR_OR_WARNING"
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Main {
|
||||
|
||||
public void test(Optional<String> opt, Function<String, Object> onPresent, Supplier<Object> onEmpty) {
|
||||
// warning level: no semantics change
|
||||
Object o = opt.is<caret>Present() ? onPresent.apply(opt.get()) : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user