Reputation: 1918
I am trying to wrap a Java method that receives variable amount of parameters, example:
void info(String var1, Object... var2);
I used the following:
def info(message: String, any: Any*): Unit = {
LOGGER.info(message, any)
}
But that doesn't work, it ends up calling an info that receives only 1 object:
void info(String var1, Object var2);
How can I solve this to call the java method that receives multiple parameters?
Thanks!
Upvotes: 2
Views: 304
Reputation: 51658
Try
def info(message: String, any: Any*): Unit = {
LOGGER.info(message, any.asInstanceOf[Seq[Object]]: _*)
}
or
def info(message: String, any: AnyRef*): Unit = {
LOGGER.info(message, any: _*)
}
without casting but not applicable to primitive types.
Upvotes: 3