Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@takawitter
Created April 21, 2016 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takawitter/1c4f0bad41ce47f6a8394210dade6cc8 to your computer and use it in GitHub Desktop.
Save takawitter/1c4f0bad41ce47f6a8394210dade6cc8 to your computer and use it in GitHub Desktop.
sample code to invoke ReflectionMethodInvoker of groovy
import org.codehaus.groovy.runtime.ReflectionMethodInvoker
class Base{}
class Derived extends Base{}
class Derived2 extends Derived{}
class Hello{
public void hello(Base b){
println "base"
}
public void hello(Derived d){
println "derived";
}
}
h = new Hello()
ReflectionMethodInvoker.invoke(h, "hello", new Base())
ReflectionMethodInvoker.invoke(h, "hello", new Derived())
ReflectionMethodInvoker.invoke(h, "hello", new Derived2())
base
derived
derived
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment