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 arg: List[AnyRef] = List ("a",Object B)
val clazz = classLoader.loadClass("com.project.Hello")
val clazzObject = clazz.newInstance()
val myMethod = clazz.getDeclaredMethod("HelloJava", classOf[List[AnyRef]])
myMethod.setAccessible(true)
val response = myMethod.invoke(clazzObject, arg)
Java
package com.project;
public class Hello {
public static String HelloJava (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? How I can resolve this issue primarily by changing java class (if not, then 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.