mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 06:39:38 +07:00
16 lines
567 B
Java
16 lines
567 B
Java
// "Replace Optional.isPresent() condition with functional style expression" "true"
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
public class Main {
|
|
private static Optional<String> test(List<Object> list) {
|
|
Optional<Object> first = list.stream().filter(obj -> obj instanceof String).findFirst();
|
|
return !fi<caret>rst.isPresent() ? Optional.empty() : Optional.of((String) first.get());
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println(test(Arrays.asList(null, null, "aa", "bbb", "c", null, "dd")));
|
|
}
|
|
} |