I'm trying to call a polymorphic method with both varargs and non varargs versions,
var logger = org.slf4j.LoggerFactory.getLogger("foo") // 1
logger.warn.("{}{}{}", 1, 2, 3) // 2
logger.warn.("{}{}{}", Array(1, 2, 3): _*) // 3
logger.warn.("{}{}{}", Array(1, 2, 3)) // 4
Line #2 does not compile, giving an “overloaded method value warn with alternatives” error.
Line #3 does not compile, giving a “no ': _*' annotation allowed here” error.
Line #4 compiles but invokes the wrong method at runtime, it calls Logger.warn(String,Object) when I need to call Logger.warn(String,Object...).
How can I call the correct method from Scala?
Compare this Java code
logger.warn("{}-{}-{}", new Integer[] {1, 2, 3});
// produces 1-2-3
With this Scala
logger.warn("{}-{}-{}", Array(1, 2, 3))
// produces [1, 2, 3]-{}-{}