Scala - ambiguous reference to overloaded definition — with varargs [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-05 00:51:47
jkl

I think that this could be a duplicate of How do I disambiguate in Scala between methods with vararg and without

Basically, it is a known java-scala-interop problem, and the only workarounds involve extra Java adapters to make accessible in Scala.

Rex Kerr

The only way I know of is to use reflection:

val ambiguous = validator.getClass.getMethods.filter(_.getName == "validate")
val wanted = ambiguous.find(_.getParameterTypes.length == 1).get
wanted.invoke(validator, toValidate).asInstanceOf[java.util.List[ConstraintViolation]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!