java.lang.NoSuchMethodException:scala.collection.immutable.$ colon $ colon [英] java.lang.NoSuchMethodException: scala.collection.immutable.$colon$colon
问题描述
我试图动态地使用使用变量作为String类型的函数,即变量将包含函数名称作为String.因此,我需要使用该变量来调用函数.
I am trying to call a function using a variable as String type dynamically i.e. variable will contain a function name as String. So, I need to call a function using that variable.
因此,我正在使用Scala反射.如果函数接受数据类型为Sting,则可以正常工作,但是会抛出错误List [Map [String,Double]]
So, I am using Scala Reflection. It is working if the function is accepting datatype as Sting, But it is throwing error List[Map[String, Double]]
我在下面的链接中引用了代码
I used below link to refer a code
and below is a test program which I am trying to test
package test
import scala.collection.immutable.Map
class DynamicaVariable {
def cat(s1: List[Map[String, Double]]) = {
println(s1)
}
}
object DynamicaVariable{
def main(args: Array[String]): Unit = {
val obj = new DynamicaVariable
val data = List(
Map("a" -> 1.0, "b" -> 267.0, "c" -> 26.0, "d" -> 2.0), Map("a" -> 1.0, "b" -> 2678.0, "c" -> 40.0, "d" -> 2.0), Map("a" -> 4.0, "b" -> 267.0, "c" -> 26.0, "d" -> 2.0), Map("a" -> 1.0, "b" -> 2678.0, "c" -> 90.0, "d" -> 17.0)
)
val functionName = "cat"
val method = obj.getClass.getMethod(functionName,data.getClass)
method.invoke(obj,data)
}
}
我的scala版本是2.11.6,我正在使用IntelliJ.我也检查了SDK版本.并取消选中scala下的在编译过程中运行工作表"
My scala version is 2.11.6 and I am using IntelliJ. I have checked the SDK version also. And unchecked the "Run worksheet in the compile process" under scala
但是仍然没有运气!任何想法都会有所帮助.谢谢!
But still no luck! Any idea will be helpful. Thanks!