java - 如何运行作为地图上的值的 lambda 表达式
问题描述
我对java很陌生,我正在尝试创建一组通过映射中的lambda表达式获取的对象。基本上,我从映射(lambda 表达式)中获取一个值并运行它以获得一个布尔值。但是,在表达式上运行 .apply 时出现错误。有想法该怎么解决这个吗?任何帮助表示赞赏。
Map<String, Predicate<IndexSub>> order_function = new HashMap<>();
order_function.put("AlternativesValues", x -> false);
order_function.put("AlternativesConstituent", x -> x.getCloseCons());
order_function.put("EquityValues", x -> false);
order_function.put("EquityCloseConstituent", x -> x.getCloseCons());
order_function.put("EquityOpenConstituent", x -> x.getOpenCons());
order_function.put("FixedValues", x -> false);
order_function.put("FixedReturns", x -> x.getCloseCons());
order_function.put("FixedStatistics", x -> x.getOpenCons());
//getCloseCons and getOpenCons return true/false
Set<String> orderable_sub = new HashSet<String>();
for (IndexSub s : tenant_subscriptions) {
//DataProduct is a string
if (order_function.get(DataProduct).apply(s) == true){
orderable_sub.add(s.getIndexId());
}
}
解决方案
推荐阅读
- vue.js - 如何使用 Vue.js 将类添加到父类或目标类
- java - 递归无限循环使我的代码损坏
- node.js - 从后端的 node.js 和 express.js 中的请求中获取客户端域名
- javascript - 使用“util.promisify”执行远程登录时出现异常
- angular - 将路由动态添加到延迟加载的模块Angular 8
- azure - 托管服务标识 (MSI) 的配置
- git - Git 状态显示未跟踪的“主”文件
- cmake - catkin make 错误,dji sdk 启动文件错误
- python - 基本的 Python 弹跳球问题(可能还有嵌套循环?)
- ruby-on-rails - 如何知道 Rails 中的 has_many 属性何时发生变化?