Method

                                               
    java.lang.Object                                          
     |                                         
     |--java.lang.reflect.AccessibleObject                                      
         |                                     
         |--java.lang.reflect.Method                                  
                                               

A Method provides information about a method on a class or interface.

Get annotations

ReturnMethodSummary
<T extends Annotation>T getAnnotation(Class<T> annotationClass) Returns this element's annotation for the specified type if such an annotation is present, else null.
Annotation[]getDeclaredAnnotations()Returns all annotations that are directly present on this element.

Get its class or interface

ReturnMethodSummary
Class<?>getDeclaringClass()Returns the Class object representing the class or interface that declares the method represented by this Method object.

Get default value for the annotation member

ReturnMethodSummary
ObjectgetDefaultValue()Returns the default value for the annotation member represented by this Method instance.

Get declared exceptions

ReturnMethodSummary
Class<?>[] getExceptionTypes()Returns an array of Class objects that represent the types of the exceptions declared to be thrown by the underlying method represented by this Method object.
Type[]getGenericExceptionTypes()Returns an array of Type objects that represent the exceptions declared to be thrown by this Method object.

Get parameter types

ReturnMethodSummary
Type[]getGenericParameterTypes()Returns an array of Type objects that represent the formal parameter types, in declaration order, of the method represented by this Method object.
Class<?>[] getParameterTypes()Returns an array of Class objects that represent the formal parameter types, in declaration order, of the method represented by this Method object.

Get return type

ReturnMethodSummary
TypegetGenericReturnType()Returns a Type object that represents the formal return type of the method represented by this Method object.
Class<?>getReturnType()Returns a Class object that represents the formal return type of the method represented by this Method object.

Get modifiers and name for this method

ReturnMethodSummary
intgetModifiers()Returns the Java language modifiers for the method represented by this Method object, as an integer.
StringgetName()Returns the name of the method represented by this Method object, as a String.

Get annotations on the formal parameters

ReturnMethodSummary
Annotation[][]getParameterAnnotations()Returns an array of arrays that represent the annotations on the formal parameters, in declaration order, of the method represented by this Method object.

Get the type variables for this method

ReturnMethodSummary
TypeVariable<Method>[] getTypeParameters()Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order.

Invoke this method

ReturnMethodSummary
Objectinvoke(Object obj, Object... args)Invokes the underlying method represented by this Method object, on the specified object with the specified parameters.

Is this method bridge method, synthetic method and has variable number of arguments

ReturnMethodSummary
booleanisBridge()Returns true if this method is a bridge method; returns false otherwise.
booleanisSynthetic()Returns true if this method is a synthetic method; returns false otherwise.
booleanisVarArgs()Returns true if this method was declared to take a variable number of arguments; returns false otherwise.

Get the string representation of the method

ReturnMethodSummary
StringtoGenericString()Returns a string describing this Method, including type parameters.
StringtoString()Returns a string describing this Method.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.