title: Convert Spark Java to Spark scala
body: <p>I am trying to convert my Java code to scala in Spark, but found it very complicated. Is it possible to convert the following Java code to scala? Thanks!</p>
  
  <hr>
  
  <pre><code>JavaPairRDD&lt;String,Tuple2&lt;String,String&gt;&gt; newDataPair = newRecords.mapToPair(new PairFunction&lt;String, String, Tuple2&lt;String, String&gt;&gt;() {
  
              private static final long serialVersionUID = 1L;
  
              @Override
              public Tuple2&lt;String, Tuple2&lt;String, String&gt;&gt; call(String t) throws Exception {
                  MyPerson p = (new Gson()).fromJson(t, MyPerson.class);
  
                  String nameAgeKey = p.getName() + "_" + p.getAge() ;
  
                  Tuple2&lt;String, String&gt; value = new Tuple2&lt;String, String&gt;(p.getNationality(), t);
                  Tuple2&lt;String, Tuple2&lt;String, String&gt;&gt; kvp =
                      new Tuple2&lt;String, Tuple2&lt;String, String&gt;&gt;(nameAgeKey.toLowerCase(), value);
                  return kvp;
              }
          });
  </code></pre>
  
  <hr>
  
  <p>I tried the following, but I am sure I have missed many things. And actually it is not clear to me how to do the override function in scala ... Please suggest or share some examples. Thank you!</p>
  
  <pre><code>val newDataPair = newRecords.mapToPair(new PairFunction&lt;String, String, Tuple2&lt;String, String&gt;&gt;() {
  
          @Override
          public val call(String t) throws Exception {
              val p = (new Gson()).fromJson(t, MyPerson.class);
              val nameAgeKey = p.getName() + "_" + p.getAge() ;
              val value = new Tuple2&lt;String, String&gt;(p.getNationality(), t);
              val kvp =
                  new Tuple2&lt;String, Tuple2&lt;String, String&gt;&gt;(nameAgeKey.toLowerCase(), value);
              return kvp;
          }
      });
  </code></pre>