在 Spark Java 应用程序中使用 Tuple2 时出现编译错误

Compilation error while using Tuple2 in Spark Java Application

我正在 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 将其显示为编译错误,因为收集调用的 return 类型是 List<Tuple2<String,Integer>>

非常感谢任何帮助。

正如@Holger 在评论中提到的,构建路径中添加了 2 个 scala-library jar。删除了早期版本,编译错误消失了。

它也有助于解决我在 IntelliJ Idea 上的问题。我调用了一个函数,其中的参数是泛型类型,以 Tuple2 作为参数。它总是显示错误,但我可以通过编译。这让我困惑了好几天。删除几个依赖的sharded-jars(其中包含与scala-libiary相关的东西)后,错误消失了。