在groovy中,如何动态调用类的静态方法?
void callMethod(Class c, String staticmethodname){
//what goes here to call the static method of class c?
}
Run Code Online (Sandbox Code Playgroud)
瞧
void callMethod(Class c, String staticmethodname){
c."$staticmethodname"()
}
class test {
static someMethod() {
println "me"
}
}
callMethod(test, "someMethod")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4812 次 |
| 最近记录: |