You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

种群中查找指定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) -> {})

解决方案

  1. 修正Lambda表达式语法:Lambda参数名不要和类名重复,改用小写参数名调用属性,写法如下:

    Store store1 = findFirst(stores, store -> store.storeId == a1);
    
  2. 匹配数据类型:
    确认Store类的storeId属性类型,若为整数类型(如int),需先将读取到的double类型ID转换为对应整数类型:

    int storeId1 = (int) a1;
    Store store1 = findFirst(stores, store -> store.storeId == storeId1);
    
  3. 校验集合类型:确保stores是Iterable<Store>类型的集合,若Qstores是查询对象,需先将其转换为可迭代的Store集合后再传入findFirst方法。


内容的提问来源于stack exchange,提问作者Miguel Barata Corrêa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 12:06:11