我在从我的 Scala 代码(scala 2.10.4)调用 Jedis(Java)时遇到了一些互操作问题。
我有一个在隐式类中实现的特征
在基础类上调用方法时出现以下错误
implicit class Redis(private val underlying: Jedis) extends com.dy.storage.Redis {
override def del(keys: String*): Long = {
underlying.del(keys: _*)
}
override def del2(keys: Seq[Array[Byte]]): Long = {
underlying.del(keys: _*)
}
}
收到以下错误(scala 2.10.4
):
no `: _*' annotation allowed here
[error] (such annotations are only allowed in arguments to *-parameters)
[error] underlying.del(keys: _*)
[error] ^
[error] /Users/avnerbarr/workspace/redis-hashed-no `: _*' annotation allowed here
[error] (such annotations are only allowed in arguments to *-parameters)
[error] underlying.del(keys: _*)
[error] ^
我尝试添加一个包装器并将有问题的调用移到隐式类之外:
override def del(keys: String*): Long = {
Wrapper.delete(underlying, keys)
}
object Wrapper {
def delete(u : Jedis, str: Seq[String]): Long = {
u.del(str:_*)
}
}
然后出现此错误:
overloaded method value del with alternatives:
[error] (x$1: String)Long <and>
[error] (x$1: <repeated...>[String])Long <and>
[error] (x$1: Array[Byte])Long <and>
[error] (x$1: <repeated...>[Array[Byte]])Long
[error] cannot be applied to (Char)
[error] u.del(a:_*)
[error] ^
[info] Checking every *.class/*.jar file's SHA-1.
[error] one error found
此代码在使用 scala 2.11 时完全没有问题,并且仅在 scala 2.10 中出现问题
是否有可能“选择”而不是推断应该调用的正确方法?