Main Page | Class Hierarchy | Class List | Directories | Class Members | Related Pages

java.lang.reflect.Method Class Reference

Inheritance diagram for java.lang.reflect.Method:

java.lang.reflect.AccessibleObject List of all members.

Detailed Description

This class must be implemented by the vm vendor.

This class models a method. Information about the method can be accessed, and the method can be invoked dynamically.


Public Member Functions

boolean equals (Object object)
 Compares the specified object to this Method and answer if they are equal.
Class getDeclaringClass ()
 Return the java.lang.Class associated with the class that defined this constructor.
Class[] getExceptionTypes ()
 Return an array of the java.lang.Class objects associated with the exceptions declared to be thrown by this method.
int getModifiers ()
 Return the modifiers for the modelled constructor.
String getName ()
 Return the name of the modelled method.
Class[] getParameterTypes ()
 Return an array of the java.lang.Class objects associated with the parameter types of this method.
Class getReturnType ()
 Return the java.lang.Class associated with the return type of this method.
int hashCode ()
 Answers an integer hash code for the receiver.
Object invoke (Object receiver, Object args[]) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
 Return the result of dynamically invoking the modelled method.
String toString ()
 Answers a string containing a concise, human-readable description of the receiver.


Member Function Documentation

boolean java.lang.reflect.Method.equals Object  object  ) 
 

Compares the specified object to this Method and answer if they are equal.

The object must be an instance of Method with the same defining class and parameter types.

Parameters:
object the object to compare
Returns:
true if the specified object is equal to this Method, false otherwise
See also:
hashCode

Class java.lang.reflect.Method.getDeclaringClass  ) 
 

Return the java.lang.Class associated with the class that defined this constructor.

Returns:
the declaring class

Class [] java.lang.reflect.Method.getExceptionTypes  ) 
 

Return an array of the java.lang.Class objects associated with the exceptions declared to be thrown by this method.

If the method was not declared to throw any exceptions, the array returned will be empty.

Returns:
the declared exception classes

int java.lang.reflect.Method.getModifiers  ) 
 

Return the modifiers for the modelled constructor.

The Modifier class should be used to decode the result.

Returns:
the modifiers
See also:
java.lang.reflect.Modifier

Reimplemented from java.lang.reflect.AccessibleObject.

String java.lang.reflect.Method.getName  ) 
 

Return the name of the modelled method.

Returns:
the name

Class [] java.lang.reflect.Method.getParameterTypes  ) 
 

Return an array of the java.lang.Class objects associated with the parameter types of this method.

If the method was declared with no parameters, the array returned will be empty.

Returns:
the parameter types

Class java.lang.reflect.Method.getReturnType  ) 
 

Return the java.lang.Class associated with the return type of this method.

Returns:
the return type

int java.lang.reflect.Method.hashCode  ) 
 

Answers an integer hash code for the receiver.

Objects which are equal answer the same value for this method. The hash code for a Method is the hash code of the method's name.

Returns:
the receiver's hash
See also:
equals

Object java.lang.reflect.Method.invoke Object  receiver,
Object  args[]
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException
 

Return the result of dynamically invoking the modelled method.

This reproduces the effect of receiver.methodName(arg1, arg2, ... , argN) This method performs the following:

  • If the modelled method is static, the receiver argument is ignored.
  • Otherwise, if the receiver is null, a NullPointerException is thrown. If the receiver is not an instance of the declaring class of the method, an IllegalArgumentException is thrown.
  • If this Method object is enforcing access control (see AccessibleObject) and the modelled method is not accessible from the current context, an IllegalAccessException is thrown.
  • If the number of arguments passed and the number of parameters do not match, an IllegalArgumentException is thrown.
  • For each argument passed:
    • If the corresponding parameter type is a base type, the argument is unwrapped. If the unwrapping fails, an IllegalArgumentException is thrown.
    • If the resulting argument cannot be converted to the parameter type via a widening conversion, an IllegalArgumentException is thrown.
  • If the modelled method is static, it is invoked directly. If it is non-static, the modelled method and the receiver are then used to perform a standard dynamic method lookup. The resulting method is then invoked.
  • If an exception is thrown during the invocation it is caught and wrapped in an InvocationTargetException. This exception is then thrown.
  • If the invocation completes normally, the return value is itself returned. If the method is declared to return a base type, the return value is first wrapped. If the return type is void, null is returned.

Parameters:
args the arguments to the constructor
Returns:
the new, initialized, object
Exceptions:
java.lang.NullPointerException if the receiver is null for a non-static method
java.lang.IllegalAccessException if the modelled method is not accessible
java.lang.IllegalArgumentException if an incorrect number of arguments are passed, the receiver is incompatible with the declaring class, or an argument could not be converted by a widening conversion
java.lang.reflect.InvocationTargetException if an exception was thrown by the invoked constructor
See also:
java.lang.reflect.AccessibleObject

String java.lang.reflect.Method.toString  ) 
 

Answers a string containing a concise, human-readable description of the receiver.

The format of the string is modifiers (if any) return type declaring class name '.' method name '(' parameter types, separated by ',' ')' If the method throws exceptions, ' throws ' exception types, separated by ',' For example: public native Object java.lang.Method.invoke(Object,Object) throws IllegalAccessException,IllegalArgumentException,InvocationTargetException

Returns:
a printable representation for the receiver


The documentation for this class was generated from the following file:
(c) Copyright 2005 The Apache Software Foundation or its licensors, as applicable.