【发布时间】:2018-06-15 10:42:33
【问题描述】:
我有以下结构
public interface ICommon{
ICommon add(ICommon other);
}
public class Foo implements ICommon{
...
ICommon add(ICommon other){
return new Bar().add(other);
}
}
public class Bar implements ICommon{
...
ICommon add(ICommon other){
...
}
}
作为复合模式的一部分。
我想使用流减少操作,但不知何故我不能强制类型推断接口。我正在使用这个。
List<Foo> list;
list.stream().reduce( new Foo(), (a,b) -> a.add(b));
我收到一个错误,ICommon 无法转换为 Foo。
我尝试强制强制转换参数但没有成功。
【问题讨论】:
标签: java java-stream reduce