Java Reference
In-Depth Information
The first form finds a public field that is either declared or inherited,
while the second finds only a declared field that need not be public. If
the named field does not exist, a NoSuchFieldException is thrown. Note
that the implicit length field of an array is not returned when these
methods are invoked on an array type.
Particular methods are identified by their signaturetheir name and a se-
quence of Class objects representing the number and type of their para-
meters. Remember that for a varargs method the last parameter will
actually be an array.
public Method
getMethod(String name, Class... parameterTypes)
public Method
getDeclaredMethod(String name, Class... parameterTypes)
Similarly, constructors are identified by their parameter number and
types:
public Constructor<T>
getConstructor(Class... parameterTypes)
public Constructor<T>
getDeclaredConstructor(Class... parameterTypes)
In both cases, if the specified method or constructor does not exist, you
will get a NoSuchMethodException .
Note that when you ask for a single constructor you get a parameterized
constructor type, Constructor<T> , that matches the type of the Class ob-
ject, while the array returned for a group of constructors is not para-
meterized by T . This is because you can't create a generic array. Any
constructor extracted from the array is essentially of an unknown kind,
but this only affects use of the invoke method, which we discuss a little
later.
 
Search WWH ::




Custom Search