Java Reference
In-Depth Information
[2] A number of methods return arrays of raw types, such as Class[] or Constructor[] . These methods
should have been generified to return wildcard types: Class<?>[] or Constructor<?>[] .
public Constructor[] getConstructors()
public Field[] getFields()
public Method[] getMethods()
public Class[] getClasses()
Because constructors are not inherited, getConstructors returns Con-
structor objects only for public constructors declared in the current
class.
You can also ask for the members of a specific kind that are actually
declared in the class (interface), as opposed to being inherited. Such
members need not be public:
public Constructor[] getDeclaredConstructors()
public Field[] getDeclaredFields()
public Method[] getDeclaredMethods()
public Class[] getDeclaredClasses()
In each case, if there is no member of that kind, you will get an empty
array. The getClasses and getdeclaredClasses methods return both nested
classes and nested interfaces.
Requesting a particular member requires you to supply further inform-
ation. For nested types this is simply the name of the nested type and,
in fact, there are no special methods to do this because Class.forName
can be used for this purpose. Particular fields are requested using their
name:
public Field getField(String name)
public Field getDeclaredField(String name)
 
 
Search WWH ::




Custom Search