【问题标题】:Collecting List with a custom list Supplier?使用自定义列表供应商收集列表?
【发布时间】:2022-06-10 19:59:31
【问题描述】:

我正在编写一个通用列表转换器,并希望收集映射结果 带有提供的列表。 clazz 参数只是一个扩展 ArrayList<CustomClass> 的 CustomClassList。 我收到编译时错误。有什么方法可以使用泛型来实现它?

protected <T, R, P extends List<? extends Serializable>>
void mapper(Function<? super T, ? extends R> mapper, List list, P clazz){
    final Supplier<P> p = () -> clazz;
    list.map(l -> mapper).collect(p::get);// compile error reason: no instance(s) of type variable(s) C, T exist so that ? extends Serializable can be converted to T
}

【问题讨论】:

  • 你的意思是p::get
  • 修复了问题

标签: java generics collections java-stream


猜你喜欢
  • 2018-10-14
  • 2018-05-03
  • 2017-06-12
  • 2023-03-26
  • 1970-01-01
  • 2012-10-31
  • 1970-01-01
  • 1970-01-01
  • 2015-07-26
相关资源
最近更新 更多