reflection - java: get all variable names in a class -
I have a class and I want to find it all public variable (not a function). How can I do so? Thanks!
field [] field = YourClassName.class.getFields ();
Returns an array of all public variables in the class.
getFields ()
return the fields in the whole class heir. If you want only the field defined in the class, and not its superwell, use getDeclaredFields ()
, and filter the public
with the following modifier < / Code> approach:
Modifier.isPublic (field.getModifiers ());
YourClassName.class
really represents one of the types of types, check your documents for its interesting reflection methods.
The above is the field
category. You can take a look at the whole package.
Comments
Post a Comment