首页 > 解决方案 > Scala.jdk.CollectionConverter

问题描述

在我的应用程序中,我使用了asScalafrom的方法,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>
        }
    }

我该如何管理?

标签: javascala

解决方案


我找到了解决方案:因为我在 java 代码上执行此操作,所以我需要使用scala.jdk.javaapi.CollectionConverters._它来使其在Java.util.List


推荐阅读