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

前端之家收集整理的这篇文章主要介绍了在groovy中,如何动态调用类的静态方法?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在groovy中,如何动态调用类的静态方法

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

解决方法

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

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

callMethod(test,"someMethod")

猜你在找的Groovy相关文章