I am using this to collect all methods a class has:
grailsApplication.getMainContext().getBean("className").metaClass.methods*.name
But this returns all the methods including the inherited ones, how can I filter only the methods owned by the class?
This will give you the list of method names filtered to include only methods belonging to only the declaring class(SomeClass
in this example):
SomeClass sc = new SomeClass()
List<String> declaringClassOnlyMethods = sc.metaClass.methods.findAll { MetaMethod method ->
if(method.declaringClass.name == sc.class.name) {
method.name
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With