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

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
doer10195
  • 35
  • 3

1 Answers1

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.)

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66