Java Google Collections API是否有Ruby Enumerable#inject方法的等价物?

Java Google Collections API是否有Ruby Enumerable#inject方法的等价物?,java,functional-programming,guava,inject,Java,Functional Programming,Guava,Inject,我通读了javadoc,找不到任何类似的东西。我认为您没有确切的注入方法。。但是,您可以使用提供的transformValues方法获得类似的解决方案 Maps.transformValues(Map<K,V1> fromMap, Function<? super V1,V2> function) List.transform(List<F> fromList, Function<? super F,? extends T> function)

我通读了javadoc,找不到任何类似的东西。

我认为您没有确切的注入方法。。但是,您可以使用提供的transformValues方法获得类似的解决方案

Maps.transformValues(Map<K,V1> fromMap, Function<? super V1,V2> function)
List.transform(List<F> fromList, Function<? super F,? extends T> function)
不,没有


虽然它确实有一些函数式编程元素(谓词、函数),但这些元素都是为了支持特定的需求,它的核心重点不是为Java添加函数式编程元素(看看它目前是多么的冗长)。请看一看。

如果您告诉我们可怜的java用户
Enumerable#inject
做了什么…@skaffman:另一个库(Jaggregate)已经尝试过了,我认为您最好还是编写自己的Reducer接口和静态reduce方法。这并不太难,至少可以让你的意图变得清晰,而不是成为一个黑客。这毫无疑问是正确的,但也许通过这种方式,你可以将它与一种应该优化的方法结合起来。。
class MyFunction<Type, Type>
{
  static String variable;

  Type apply(Type t)
  {
     //do whatever you want with t
     // and storing intermediate result to variable

     // return same t to make this function work like identity
     return t;
  }

}