我试图在Scala中使用库dcm4che3。
我的Scala代码是
val item: Attributes = new Attributes
val x: Int = ints.toArray.length
val vr: VR = VR.OW
val intArray: Array[Int] = ints.toArray
item.setInt(Tag.LUTData, vr, intArray)我得到了一个错误
Error:(125, 10) overloaded method value setInt with alternatives:
(x$1: String,x$2: Int,x$3: org.dcm4che3.data.VR,x$4: Int*)Object <and>
(x$1: Int,x$2: org.dcm4che3.data.VR,x$3: Int*)Object
cannot be applied to (Int, org.dcm4che3.data.VR, Array[Int])
item.setInt(Tag.LUTData, vr, intArray)我注意到在错误中它要求一个Int*。java签名是
setInt(int,org.dcm4che3.data.VR,int[])据我所知,ArrayInt是int[]的scala。什么是Int*?为什么这个不行?
发布于 2015-10-29 11:27:52
Int*是一个varargs参数,相当于int...。就像Java一样,您可以传递数组或任意数量的参数,但是为了避免在传递null时在Java中出现的模糊性,Scala中有一种特殊的语法。按以下方式调用该函数:
item.setInt(Tag.LUTData, vr, intArray:_*)实际上,您可能根本不需要数组:可以将任何序列传递给Scala中的varargs函数,而不仅仅是数组,因此如果您的ints变量是某种序列,则可以传递它代替intArray,并完全删除intArray。
请参见 (colon underscore star) do in Scala?,这与您的问题相反。
https://stackoverflow.com/questions/33412789
复制相似问题