作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在 Java 8 中,我有一个变量,包含一个可选的 boolean 值。
如果可选不为空且包含的 boolean 值为真,我希望执行一个 Action 。
我梦想着像 ifPresentAndTrue
这样的东西,这里有一个完整的例子:
import java.util.Optional;
public class X {
public static void main(String[] args) {
Optional<Boolean> spouseIsMale = Optional.of(true);
spouseIsMale.ifPresentAndTrue(b -> System.out.println("There is a male spouse."));
}
}
最佳答案
为了良好的秩序
if (spouseIsMale.orElse(false)) {
System.out.println("There is a male spouse.");
}
清除。
关于java - 如果可选 boolean 值为真,如何执行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46766422/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!