1

I am trying to use the library dcm4che3 in Scala

My Scala code is

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)

and I get an error

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)

I notice in the error it is asking for an Int*. The java signature is

setInt(int,org.dcm4che3.data.VR,int[])

I understand that Array[Int] is the scala equivalent of int[]. What is an Int*? Why doesn't this work?

1
  • 1
    it's a seq. can you try: intArray: _* Commented Oct 29, 2015 at 11:27

1 Answer 1

3

Int* is a varargs parameter, the equivalent of Java's int.... Just like Java, you can pass an array or an arbitrary number of arguments, but to avoid the ambiguity you get in Java when you pass null, there's a special syntax in Scala. Call the function as follows:-

item.setInt(Tag.LUTData, vr, intArray:_*)

In fact, you probably don't need an array at all: you can pass any sequence to a varargs function in Scala, not just an array, so if your ints variable is some kind of sequence, you can pass it in place of intArray, and remove intArray completely.

See also What does `:_*` (colon underscore star) do in Scala?, which is the reverse of your question.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.