I just noticed that implicit def
doesn't seem to work in var args.
For example, I have a java function that takes java.lang.Byte...
as its parameter input. The function call is surround by a scala method that takes scala.Byte
.
implicit def convertTest(bytes: Byte*): Seq[java.lang.Byte] = bytes.map(b => b : java.lang.Byte)
def test(data: Byte*): Unit ={
test2(convertTest(data: _*): _*)
}
def test2(data: java.lang.Byte*) = {
}
For some reason I have to explicitly type convertTest()
for this to work.
So I tried something without the varargs
parameter and found that indeed if I do this, it works:
implicit def convertTest(bytes: List[Byte]): java.util.List[java.lang.Byte] = bytes.map(b => b : java.lang.Byte).asJava
def test(data: List[Byte]): Unit ={
test2(data)
}
def test2(data: java.util.List[java.lang.Byte]) = {
}
Can someone please explain this to me?