java - 错误->“com.google.gson.internal.LinkedTreeMap 无法转换为”使用 Stream.filter
问题描述
尝试使用 Stream.filter 获取子列表过滤器时出现此异常:
List<Presupuesto> PresupuestosTienda = presupuestos.stream().filter(item -> item.tienda.equals(LaTienda.nombre)).collect(Collectors.toList());
- 'presupuestos' 也是一个
List<Presupuesto>
。
我的 Presupuesto 课程非常简单:
public class Presupuesto {
String vendedor, tienda;
Date fecha;
double total;
public Presupuesto(){
}
public Presupuesto(String vendedor, String tienda, Date fecha, double total){
this.vendedor=vendedor;
this.tienda=tienda;
this.fecha=fecha;
this.total=total;
}
}
我真的不知道为什么会这样。我从互联网上举了一个例子,它有效!没有太大区别。
有人知道会发生什么吗?非常感谢
解决方案
我发现由于我的 List 的来源是一个用 gson 转换的 Json,所以 List 中每个元素的真实类型是 LinkedTreeMap 而不是 Presupuesto 类 Type。所以知道我的问题是其他的。谢谢
推荐阅读
- pyspark - 如何在pyspark数据帧(时间序列)中计算每日基础
- python - Python 交互式窗口不断打开脚本或运行它
- javascript - 如何在具有 src 的标签中附加 thymeleaf 变量?
- c - 使用 C 生成位图图像:第一行像素损坏
- python - 如何用 pip 替换现有环境来重现 Python 环境?
- android - 在第二个列表中查找丢失对象然后使用 Kotlin 添加它的更好方法
- javascript - 过滤从 Promise 返回的数组
- keras - 如何使用 scikit learn 的 MLP 分类器可视化模型训练历史?
- postgresql - 无法重新连接到 postgresql 数据库
- python - 不确定 tensorflow 是否在 GPU 或 CPU 自定义 keras 训练循环上运行,或者它是否与训练循环代码有关