Java reflection Once we have a Class object
Java reflection Once we have a Class object for our class, we may use methods such as getConstructors(), getMethods(), and getFields() to retrieve information about this class. The Method class For the purpose of this book, the class most important to us is Method, mainly because, by obtaining a Method object from a certain class, we are able to call that method repeatedly and on any instance of this class. This is the approach we will use to call the get and set property methods within the custom JavaBean tags we are building. The methods that are part of the Method class are presented in table 8.2, along with a brief description of each. Table 8.2 Methods in the Method class Method name Description getDeclaringClass() Returns a Class object that represents the class or interface to which that method belongs. Think of it as the Class object that, if you call one of its getMethod() methods, will return this as the Method object. getModifiers() Returns an integer representation of Java language modifiers. Later on, the Modifier utility class can decode this integer. getName() Returns the name of the method. getParameterTypes() Returns an array of Class objects that represent the parameter types, in declaration order, of the method. getReturnType() Returns a Class object that represents the return type of the method. invoke(Object obj, Object[] args) Invokes the underlying method on the specified object with the specified parameters. getExceptionTypes() Returns an array of Class objects representing the types of exceptions declared to be thrown by the method. equals(Object obj) Compares this Method against the specified object. hashCode() Returns a hashcode for this Method. toString() Returns a string describing this Method. Some of the methods mentioned in table 8.2, such as equals(), hashCode(), and toString() do not require any real explanation, as anyone familiar with Java programming knows how and when to use these methods. The remainder of the methods, however, require some ground rules:
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services