Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy read feature methods with reflection

I am trying to use reflection to read fields and methods from a groovy class. Everything works great expect my feature methods like this:

def "do something"(){
//
}

Using reflection I cannot find this "method name". Is there any way to read these feature methods by reflection?

Thanks in advance!

like image 683
user40369 Avatar asked Dec 03 '25 09:12

user40369


1 Answers

You can find it with metaClass:

class Lol {
    def 'do something'(){}
}

assert new Lol().metaClass.methods.find { it.name == 'do something' }
like image 151
Opal Avatar answered Dec 04 '25 22:12

Opal