- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
invoke method with an array using reflection
Thu, 2009-03-12, 16:08
Hi all.
I have a problem with the following snipplet:
class PiArr {
var intArr:Array[Int] = _
}
object ReflectTest {
def main(args : Array[String]) : Unit = {
val pa = new PiArr()
val mthd = pa.getClass.getMethods.find(_.getName == "intArr_$eq" ).get
val ar1 = new Array[Int](4)
ar1(0) = 12
ar1(1) = 13
ar1(2) = 14
ar1(3) = 14
mthd.invoke(ar1) // fail :
mthd.invoke(Array(1, 4, 5)) // fail
}
}
Both mthd.invoke fail with the exception:
java.lang.IllegalArgumentException: object is not an instance of declaring class
Is it the expected behaviour? Is there a way to make it working?
thanks
G