mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-01 19:02:04 +07:00
GitOrigin-RevId: bb857fbf79fd224406b37ad2a40dd33445575514
15 lines
505 B
Java
15 lines
505 B
Java
import java.util.stream.*;
|
|
import java.util.*;
|
|
|
|
public class OptionalGetMethodReference {
|
|
public static void main(String[] args) {
|
|
Stream.of(Optional.ofNullable(Math.random() > 0.5 ? 1 : null))
|
|
.map(<warning descr="'Optional::get' without 'isPresent()' check">Optional::get</warning>)
|
|
.forEach(System.out::println);
|
|
|
|
Stream.of(Optional.ofNullable(Math.random() > 0.5 ? 1 : null))
|
|
.filter(Optional::isPresent)
|
|
.map(Optional::get)
|
|
.forEach(System.out::println);
|
|
}
|
|
} |