我是Scala的新手,目前正在一个涉及Java和Scala模块的项目中工作。现在我想使用类型为byte[]的参数从Java调用Scala方法。
Scala方法的签名为:def foo(data: Array[Byte])
Java调用看起来像这样:foo(x)
,其中x的类型为byte[]
。
IDE告诉我这是不可能的:
The method foo(Array) in the type Bar is not applicable for the arguments (byte[])
作为附加限制条件,不建议更改Scala方法。在Java端,我尝试使用Byte[]
,但这并没有解决问题。必须存在某种转换吗?
Array [Byte]
从2.8开始就是byte []
,如果你的IDE报错了,那么你的IDE是错误的。 - Rex Kerrscala.Array
的x调用foo(x)
会让我的IDE返回:The method foo(byte[]) in the type Bar is not applicable for the arguments (Array)
。这就是我所说的矛盾行为。我应该尝试在其他地方编译代码... - mtsz