2

I'm currently working in a Kotlin file with ValueAnimator's ofObject method: ValueAnimator.ofObject(TypeEvaluator evaluator, Object... values) in Android.

I have a Kotlin IntArray e.g.. fooIntArray that contains the values I need to pass into the varargs as individual objects. I've tried using the Spread * operator as follows: ValueAnimator.ofObject(someEvaluator, *fooIntArray, but the types aren't correct and I've tried to figure out how to cast fooIntArray to something like *fooIntArray as Array<Any> with no luck.

While working in Java with an int[] eg. fooIntArray, the only way I was able to successfully pass the int array was to cast it like this: ValueAnimator.ofObject(someEvaluator, (Object[] fooIntArray).

Does anyone have suggestions on how could I achieve the same thing in Kotlin?

1 Answer 1

4

The toTypedArray function (the name of which is unfortunately confusing for this case) will convert the array of primitive integers into an array of boxed integers, after which you can use the spread operator to pass it to the method:

ValueAnimator.ofObject(someEvaluator, *fooIntArray.toTypedArray())
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.