种群中查找指定Store代理报错:findFirst函数参数不匹配问题排查
配送订单项目中关联门店ID与Store对象的问题
项目背景
- 正在开展一个配送项目,需导入不同门店的订单数据集,同时导入包含各配送货车必须执行的门店ID序列的数据集。每个门店都分配有GIS点,项目目标是让货车按指定路线为不同门店配送订单。
- 已创建
Order类,包含4个参数:quantity:运输货物的数量store1/store2/store3:依次为货车需要前往的配送门店
- 当前需要创建
Order对象,但需将路线数据集中的门店ID与已从门店数据集创建好的Store对象关联起来。
尝试的代码
for(int i=0; i < excelFile.getLastRowNum("Sheet1");i++){ double amnt=excelFile.getCellNumericValue("Sheet1", i+2, 4); double a1=excelFile.getCellNumericValue("Sheet1", i+2, 5); // 第一个门店的ID所在单元格 double a2=excelFile.getCellNumericValue("Sheet1", i+2, 6); // 第二个门店的ID所在单元格 double a3=excelFile.getCellNumericValue("Sheet1", i+2, 7); // 第三个门店的ID所在单元格 Store store1=findFirst(stores, Store -> Store.storeId == a1); Store store2=findFirst(stores, Store -> Store.storeId == a2); Store store3=findFirst(stores, Store -> Store.storeId == a3); Order order = new Order(amnt,store1,store2,store3); }
遇到的错误
错误描述:
UtilitiesCollection类中的findFirst(Iterable, Predicate<? super T>)方法不适用于给定的参数(Qstores, ( Store) -> {})
解决方案
修正Lambda表达式语法:Lambda参数名不要和类名重复,改用小写参数名调用属性,写法如下:
Store store1 = findFirst(stores, store -> store.storeId == a1);匹配数据类型:
确认Store类的storeId属性类型,若为整数类型(如int),需先将读取到的double类型ID转换为对应整数类型:int storeId1 = (int) a1; Store store1 = findFirst(stores, store -> store.storeId == storeId1);校验集合类型:确保
stores是Iterable<Store>类型的集合,若Qstores是查询对象,需先将其转换为可迭代的Store集合后再传入findFirst方法。
内容的提问来源于stack exchange,提问作者Miguel Barata Corrêa
相关产品推荐
相关产品推荐

