我需要在我的一个scala文件中获取方法的参数名称。我知道,通过使用-parameter
编译器选项,我可以用Java工作。但是,我无法在scala中执行此操作,因为我在scalac中找不到-parameter选项。
我怎样才能做到这一点? 我在SO中看到this回答,但这是一个陈旧的答案。 scala(2.11)中是不可能的,因为这个选项只出现在java8中?有什么黑客攻击吗?
编辑:(添加示例scala代码)
class ReflectionTest {
def method(name: String, id: Long, desc: String) = {
println("Inside the method");
}
}
我正在尝试阅读ReflectionTest
类method()
object Test extends App {
val methods= Class.forName("com.reflection.ReflectionTest").getMethods
methods filter(_.getName == "method") map { method =>
val param = method.getParameters
param.map {p =>
println("Method : "+method.getName+" , Parameter : "+p.getName)
}
}
}
Scala版本:2.11.2
JDK版本:1.8
SBT版本:0.13.1