How to get all the variables of a groovy object or class?
groovy
Solution
You could do:
String.metaClass.properties.each { println it.name }
An alternative (given your new example) would be:
import java.lang.reflect.Modifier
HoneyBadger.declaredFields
.findAll { !it.synthetic }
.each { println "${Modifier.toString( it.modifiers )} ${it.name} : ${it.type}" }
Problem
To see list of methods in a class I can do this - ``` String.methods.each {println it} ``` How do I list all the variables of an instance or all the static variables of a class? Edit1: Edit2: HoneyBadger.java ``` public class HoneyBadger { public int badassFactor; protected int emoFactor; private int sleepTime; } ``` test.groovy - ``` HoneyBadger.metaClass.properties.each {println it.name } ``` Output - ``` class ```