Scala 游戏框架中的配对列表

Scala 游戏框架中的配对列表,scala,playframework,playframework-2.0,Scala,Playframework,Playframework 2.0,我有一个成对的数组列表- public static ArrayList<Pair<String, String>> fields; 现在在index.scala.html中,我有了 @(fields : List[(String,String)]) 但这给了我类型不匹配的编译错误。 scala中不支持对吗?或者我应该使用其他语法来实现这一点 Scala for Java Pair中是否有兼容的类型?您的字段值的类型为Java.util.ArrayList,但ind

我有一个成对的数组列表-

public static ArrayList<Pair<String, String>> fields;

现在在index.scala.html中,我有了

@(fields : List[(String,String)])
但这给了我类型不匹配的编译错误。
scala中不支持对吗?或者我应该使用其他语法来实现这一点


Scala for Java Pair中是否有兼容的类型?

您的
字段
值的类型为
Java.util.ArrayList
,但index.Scala.html所需的参数是
Scala.collection.immutable.List
-因此类型不匹配。

这是由于类型不匹配造成的。它需要
scala.collection.immutable.List[(String,String)]
但是您要传递的是
java.util.List[(String,String)]

要解决此问题,请执行以下操作:

import scala.collection.JavaConverters._
return ok(index.render(fields.asScala.toList));

请在index.scala.html中尝试以下内容:

@import java.util
@(fields : util.List[(String,String)])

当我传递一个ArrayList以列表[String]的形式查看和接收它时,它工作正常。我认为问题出在这对情侣身上。scala中是否有兼容的Pair类型?@user2694377 Hmm,好的-那么
字段中的
Pair
类型来自哪里?scala.Predef(在scala中自动导入)中定义了一个类型类
Pair
,它等同于Tuple2-您是在使用它,还是在使用其他东西(可能定义为Java类/接口)?
@import java.util
@(fields : util.List[(String,String)])