我正在 Eclipse Luna 中使用 Java 1.8 尝试 Spark 编程示例,并具有以下代码 -
JavaPairRDD<String, Integer> counts = ones
.reduceByKey(new Function2<Integer, Integer, Integer>() {
@Override
public Integer call(Integer i1, Integer i2) {
return i1 + i2;
}
});
List<Tuple2<String, Integer>> output = counts.collect(); //Compilation Error
我正在使用M2Eclipse构建和创建jar,并使用spark-submit在我的本地执行jar。 jar 正在工作并打印正确的输出,但 Eclipse 始终将上述行显示为编译错误 - The type Tuple2 is not generic; it cannot be parameterized with arguments <String, Integer>
甚至 Spark 网页中引用的编程示例也使用与 Tuple2 相同的表示法。 https://spark.apache.org/docs/0.9.0/java-programming-guide.html
我无法理解为什么 Eclipse 将其显示为编译错误,因为收集调用的返回类型是 List<Tuple2<String,Integer>>
非常感谢任何帮助。
最佳答案
正如 @Holger 在评论中提到的,2 个 scala-library jar 已添加到构建路径中。删除了早期版本,编译错误消失了。
关于java - 在 Spark Java 应用程序中使用 Tuple2 时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30848217/