Reputation: 15074
I needed to convert an array of AnyRef (java function argument) to a tuple of Ints. I tried the accepted answer from here, but this didn't work for me because in that question it was assumed that the array was an array of Any, not an array of AnyRef.
Upvotes: 0
Views: 1642
Reputation: 15074
In the end, the code that worked for me looked as follows:
val (x, y) = args match { case Array(x: Integer, y: Integer, _*) => (x, y) }
Note the use of the boxing class Integer rather than Int to deal with the fact that we are sourcing from auto-boxed AnyRefs (java Objects).
Upvotes: 3