java - Scala.jdk.CollectionConverter
问题描述
在我的应用程序中,我使用了asScala
from的方法,scala.collection.JavaConverters._
但是在运行时我收到警告,自 2.13.0 起,该方法已被弃用scala.jdk.CollectionConverters._
。
但是当我尝试在我的 Java List 上使用它时,我一直遇到这个错误:
type mismatch;
found : java.util.List[play.data.validation.ValidationError]
required: ?{def asScala: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method asScalaBufferConverter in object JavaConverters of type [A](l: java.util.List[A])collection.JavaConverters.AsScala[scala.collection.mutable.Buffer[A]]
and method ListHasAsScala in trait AsScalaExtensions of type [A](l: java.util.List[A])jdk.CollectionConverters.ListHasAsScala[A]
are possible conversion functions from java.util.List[play.data.validation.ValidationError] to ?{def asScala: ?}
即使我不导入scala.collection.JavaConverters._
.
我正在使用播放框架 2.7.3 进行编码,我的视图(旋转模板)有一个参数form: Form[InformationData]
,并且错误发生在此
@if(form.hasGlobalErrors) {
@form.globalErrors.asScala.map { error: play.data.validation.ValidationError =>
<div>
@error.key: @error.message
</div>
}
}
我该如何管理?
解决方案
我找到了解决方案:因为我在 java 代码上执行此操作,所以我需要使用scala.jdk.javaapi.CollectionConverters._
它来使其在Java.util.List
推荐阅读
- three.js - Threejs网格矩阵getInverse Uncaught TypeError:无法读取未定义的属性“元素”
- python - 为什么我应该解决时仍然收到“NoneType”错误?
- spring-boot - 将以下划线“_”开头的请求参数(GET 查询)绑定到 bean 属性
- java - 如何写一个 Dockerfile 依赖于其他镜像
- python-3.x - 如何在 Alexa-host 自定义技能中将 feedparser 作为外部包导入
- mongodb - Mongorestore 问题 身份验证失败
- python - 如何更改或删除 GeoTIFF 标签?
- c# - C# VSTO Excel 自动筛选值和空白
- python - 无法使用 python adodbapi 库建立数据库连接
- sql-server - SQL Server - Recursive Query to Return Distinct Email/Phone Relative to a Given Email