2
試圖寫一個封裝到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])
這是怎麼回事?
請參閱[http://stackoverflow.com/questions/4325086/why-is-scalas-behavior-in-case-of-overloading-with-by-name-parameters-different][1]中的說明 [1]:http://stackoverflow.com/questions/4325086/why-is-scalas-behavior-in-case-of-overloading-with-by-name-parameters-different –