Scala-对重载定义的模棱两可引用-使用varargs [英] Scala - ambiguous reference to overloaded definition -- with varargs
本文介绍了Scala-对重载定义的模棱两可引用-使用varargs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
How do I disambiguate in Scala between methods with vararg and without
我目前正在将应用程序的一部分移植到scala,它使用Oval库.问题的方法是Validator.validate方法.它具有两个
I am currently porting part of an application to scala and it uses the Oval library. The method is question is the Validator.validate method. It has two signatures:
List<ConstraintViolation> validate(Object validatedObject)
List<ConstraintViolation> validate(Object validatedObject, String... profiles)
scala代码通常如下所示:
The scala code looks generally like this:
def validate(toValidate: AnyRef) = {
val validator = createValidator
validator.validate(toValidate)
}
错误消息:
error: ambiguous reference to overloaded definition,
[INFO] both method validate in class Validator of type (x$1: Any,x$2: <repeated...>[java.lang.String])java.util.List[net.sf.oval.ConstraintViolation]
[INFO] and method validate in class Validator of type (x$1: Any)java.util.List[net.sf.oval.ConstraintViolation]
[INFO] match argument types (AnyRef)
[INFO] this.validator.validate(toValidate)
我如何才能做到这一点?
How can I get this be be unambiguous?
推荐答案
我认为这可能与基本上,这是一个已知的java-scala-interop问题,唯一的解决方法是使额外的Java适配器在Scala中可访问.
Basically, it is a known java-scala-interop problem, and the only workarounds involve extra Java adapters to make accessible in Scala.
这篇关于Scala-对重载定义的模棱两可引用-使用varargs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文