Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In groovy, how do you dynamically call a static method of a class?

Tags:

groovy

In groovy, how do you dynamically call a static method of a class?

void callMethod(Class c, String staticmethodname){
     //what goes here to call the static method of class c?
}
like image 933
Kyle Avatar asked Oct 21 '25 18:10

Kyle


1 Answers

Voila

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

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

callMethod(test, "someMethod")
like image 95
mfloryan Avatar answered Oct 23 '25 16:10

mfloryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!