【问题标题】:Java and Scala Tuple2 Access ErrorJava 和 Scala Tuple2 访问错误
【发布时间】:2023-03-31 20:35:01
【问题描述】:

我正在处理Data Algorithms 的书和

尝试访问 Java 中的 Tuple2 成员时出现以下编译错误:

我承认,我对 Scala 很陌生,但语法看起来是正确的,每个 scala-lang,所以任何帮助表示赞赏。谢谢

_1 has private access in scala.Tuple2
_2 has private access in scala.Tuple2

有问题的代码sn-p

List<Tuple2<String, Iterable<Tuple2<Integer,Integer>>>> output2 = groups.collect();
for(Tuple2<String, Iterable<Tuple2<Integer,Integer>>> t : output2){

        Iterable<Tuple2<Integer,Integer>> list = t._2;
        System.out.println(t._1);
        for(Tuple2<Integer,Integer> t2 : list){

                System.out.println(t2._1 + "," + t2._2);
        }

}

【问题讨论】:

    标签: java scala apache-spark tuples


    【解决方案1】:

    你必须在java中包含括号。 t2._2()t2._1()。 Scala 有一个快捷方式,可以在零参数方法中省略括号。

    【讨论】:

      猜你喜欢
      • 2016-09-15
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      • 1970-01-01
      • 2015-09-13
      相关资源
      最近更新 更多