在groovy中,如何动态调用类的静态方法?

Kyl*_*yle 3 groovy

在groovy中,如何动态调用类的静态方法?

void callMethod(Class c, String staticmethodname){
     //what goes here to call the static method of class c?
}
Run Code Online (Sandbox Code Playgroud)

mfl*_*yan 7

瞧

void callMethod(Class c, String staticmethodname){
     c."$staticmethodname"()
}

class test {
  static someMethod() {
    println "me"
  }
}

callMethod(test, "someMethod")
Run Code Online (Sandbox Code Playgroud)