0

I am using Java Reflection in Scala, However when I try to invoke the function I am getting the following Error : java.lang.IllegalArgumentException: argument type mismatch

Following function present in testClass

def test(mystr:String):String ={
  return "hi"
}

I am calling the above function the following way

var params = new Array[Object](1)
params(0) = "hi"

//extractOject is instance of testClass
val featuresJsonStr = extractFunction.invoke(extractOject,params)

I read that invoke function expects parameters of function as array of objects, I am trying to do the same thing here

1 Answer 1

3

You forgot to use varargs syntax in Scala

val featuresJsonStr = extractFunction.invoke(extractOject, params: _*) // hi

How to pass Scala array into Scala vararg method?

Or just

val featuresJsonStr = extractFunction.invoke(extractOject, "hi") // hi

(Please don't use return keyword in Scala.)

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.