import java.util.Optional;
public class Optional1 {
public static void main(String[] args) {
Optional<String> optional = Optional.of("bam");
optional.isPresent(); // true
optional.get(); // "bam"
optional.orElse("fallback"); // "bam"
optional.ifPresent((s) -> System.out.println(s.charAt(0))); // "b"
}
}
转载于:https://www.cnblogs.com/bilaisheng/p/10210909.html