试图为 slf4j 编写一个包装器。
写了方法。其中2个是:
def logWarn(message: => String, arg1: => AnyRef) = {
if (logger.isWarnEnabled) {
logger.warn(message, arg1)
}
}
def logWarn(message: => String, args: => Array[AnyRef]) = {
if (logger.isWarnEnabled) {
logger.warn(message, args)
}
}
这编译得很好。问题是试图调用:
logWarn("retried: {}. Error is: {}", Array[AnyRef](numOfRetries.toString(), e.toString()));
我希望 Scala 知道我的意思是调用上面的第二种方法。由于某些原因,我收到此错误:
ambiguous reference to overloaded definition, both method logWarn in trait Slf4jLogger of type
(message: => String, args: => Array[AnyRef])Unit
and method logWarn in trait Slf4jLogger of type (message: => String, arg1: => AnyRef)Unit
match argument types (java.lang.String,Array[AnyRef])
这是怎么回事?