I am trying to use reflection to call my java method from a scala class.
I referred this post. scala: what's the difference between Any and AnyRef? and my "arg" passed from Scala is a List[AnyRef]
Scala
val myMethod = clazz.getDeclaredMethod(methodName, classOf[List[AnyRef]])
myMethod.setAccessible(true)
val response = myMethod.invoke(clazzObject, arg)
Java
public class JavaHello {
public static String printString(List<Object> arg) {
}
While invoking this method, I am getting below exception - java.lang.NoSuchMethodException: com.Project.Hello(scala.collection.immutable.List) at java.lang.Class.getDeclaredMethod
However, calling scala class from scala works fine with the same method signature.
Can someone please help in clarifying the concept and tell me what I am doing wrong and how I can resolve this issue primarily by changing java class (if not, then some changes to the scala class). I looked at other posts as well which refers to use javaconversions and javaconverters, but that didn't help either.
Aucun commentaire:
Enregistrer un commentaire