gpt4 book ai didi

scala - Play Framework 中的对列表

转载 作者:行者123 更新时间:2023-12-02 01:58:48 26 4
gpt4 key购买 nike

我有一个对数组列表 -

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

在我的 Controller 中,我使用
呈现此列表以查看

return ok(index.render(fields));


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

@(fields : List[(String,String)])

但这给了我类型不匹配的编译错误。
Scala 不支持配对吗?或者我应该使用其他一些语法来实现这一目标吗?

Scala 中有兼容 Java Pair 的类型吗?

最佳答案

嗯,这是由于类型不匹配。它期望 scala.collection.immutable.List[(String,String)]但你却传递了 java.util.List[(String,String)] .

要解决它,请执行以下操作:

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

关于scala - Play Framework 中的对列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18356056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com