在緩衝區調用foldLeft我想打電話給在斯卡拉Buffer
的foldLeft
方法,從Java代碼:從Java
List<Integer> javaList = new ArrayList<>();
javaList.add(1);
javaList.add(3);
javaList.add(5);
Buffer<Integer> scalaBuffer = JavaConversions.asScalaBuffer(javaList);
scalaBuffer.foldLeft(0, new Function2<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer accumulator, Integer element) {
return carry + element;
}
});
,但我得到以下編譯器錯誤:
Multiple markers at this line
- The type new Function2<Integer,Integer,Integer>(){} must implement the
inherited abstract method Function2<Integer,Integer,Integer>.apply$mcVDI
$sp(double, int)
- The type new Function2<Integer,Integer,Integer>(){} must implement the
inherited abstract method Function2<Integer,Integer,Integer>.tupled$mcIDD$sp()
- The type new Function2<Integer,Integer,Integer>(){} must implement the
inherited abstract method Function2<Integer,Integer,Integer>.tupled$mcVJJ$sp()
- The type new Function2<Integer,Integer,Integer>(){} must implement the
inherited abstract method Function2<Integer,Integer,Integer>.apply$mcZDJ
$sp(double, long)
.
.
.
基本上,我必須實施一些我不感興趣的方法。
有沒有簡單的解決方案,調用foldLeft方法上的單子,從Java?
感謝, 約翰
(使用Scala的2.10-M5和JDK 1.7)
你贏了。兩個答案都是正確的。你有一個包名和一個鏈接,所以它稍微好一些。 – 2012-07-25 22:59:26