< prev index next >

src/java.base/share/classes/java/lang/reflect/Method.java

Print this page




  25 
  26 package java.lang.reflect;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.misc.SharedSecrets;
  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.MethodAccessor;
  32 import jdk.internal.reflect.Reflection;
  33 import jdk.internal.vm.annotation.ForceInline;
  34 import sun.reflect.annotation.ExceptionProxy;
  35 import sun.reflect.annotation.TypeNotPresentExceptionProxy;
  36 import sun.reflect.generics.repository.MethodRepository;
  37 import sun.reflect.generics.factory.CoreReflectionFactory;
  38 import sun.reflect.generics.factory.GenericsFactory;
  39 import sun.reflect.generics.scope.MethodScope;
  40 import sun.reflect.annotation.AnnotationType;
  41 import sun.reflect.annotation.AnnotationParser;
  42 import java.lang.annotation.Annotation;
  43 import java.lang.annotation.AnnotationFormatError;
  44 import java.nio.ByteBuffer;

  45 
  46 /**
  47  * A {@code Method} provides information about, and access to, a single method
  48  * on a class or interface.  The reflected method may be a class method
  49  * or an instance method (including an abstract method).
  50  *
  51  * <p>A {@code Method} permits widening conversions to occur when matching the
  52  * actual parameters to invoke with the underlying method's formal
  53  * parameters, but it throws an {@code IllegalArgumentException} if a
  54  * narrowing conversion would occur.
  55  *
  56  * @see Member
  57  * @see java.lang.Class
  58  * @see java.lang.Class#getMethods()
  59  * @see java.lang.Class#getMethod(String, Class[])
  60  * @see java.lang.Class#getDeclaredMethods()
  61  * @see java.lang.Class#getDeclaredMethod(String, Class[])
  62  *
  63  * @author Kenneth Russell
  64  * @author Nakul Saraiya


 399      * @return a string describing this {@code Method}
 400      *
 401      * @jls 8.4.3 Method Modifiers
 402      * @jls 9.4   Method Declarations
 403      * @jls 9.6.1 Annotation Type Elements
 404      */
 405     public String toString() {
 406         return sharedToString(Modifier.methodModifiers(),
 407                               isDefault(),
 408                               parameterTypes,
 409                               exceptionTypes);
 410     }
 411 
 412     @Override
 413     void specificToStringHeader(StringBuilder sb) {
 414         sb.append(getReturnType().getTypeName()).append(' ');
 415         sb.append(getDeclaringClass().getTypeName()).append('.');
 416         sb.append(getName());
 417     }
 418 















 419     /**
 420      * Returns a string describing this {@code Method}, including
 421      * type parameters.  The string is formatted as the method access
 422      * modifiers, if any, followed by an angle-bracketed
 423      * comma-separated list of the method's type parameters, if any,
 424      * followed by the method's generic return type, followed by a
 425      * space, followed by the class declaring the method, followed by
 426      * a period, followed by the method name, followed by a
 427      * parenthesized, comma-separated list of the method's generic
 428      * formal parameter types.
 429      *
 430      * If this method was declared to take a variable number of
 431      * arguments, instead of denoting the last parameter as
 432      * "<code><i>Type</i>[]</code>", it is denoted as
 433      * "<code><i>Type</i>...</code>".
 434      *
 435      * A space is used to separate access modifiers from one another
 436      * and from the type parameters or return type.  If there are no
 437      * type parameters, the type parameter list is elided; if the type
 438      * parameter list is present, a space separates the list from the




  25 
  26 package java.lang.reflect;
  27 
  28 import jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.misc.SharedSecrets;
  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.MethodAccessor;
  32 import jdk.internal.reflect.Reflection;
  33 import jdk.internal.vm.annotation.ForceInline;
  34 import sun.reflect.annotation.ExceptionProxy;
  35 import sun.reflect.annotation.TypeNotPresentExceptionProxy;
  36 import sun.reflect.generics.repository.MethodRepository;
  37 import sun.reflect.generics.factory.CoreReflectionFactory;
  38 import sun.reflect.generics.factory.GenericsFactory;
  39 import sun.reflect.generics.scope.MethodScope;
  40 import sun.reflect.annotation.AnnotationType;
  41 import sun.reflect.annotation.AnnotationParser;
  42 import java.lang.annotation.Annotation;
  43 import java.lang.annotation.AnnotationFormatError;
  44 import java.nio.ByteBuffer;
  45 import java.util.StringJoiner;
  46 
  47 /**
  48  * A {@code Method} provides information about, and access to, a single method
  49  * on a class or interface.  The reflected method may be a class method
  50  * or an instance method (including an abstract method).
  51  *
  52  * <p>A {@code Method} permits widening conversions to occur when matching the
  53  * actual parameters to invoke with the underlying method's formal
  54  * parameters, but it throws an {@code IllegalArgumentException} if a
  55  * narrowing conversion would occur.
  56  *
  57  * @see Member
  58  * @see java.lang.Class
  59  * @see java.lang.Class#getMethods()
  60  * @see java.lang.Class#getMethod(String, Class[])
  61  * @see java.lang.Class#getDeclaredMethods()
  62  * @see java.lang.Class#getDeclaredMethod(String, Class[])
  63  *
  64  * @author Kenneth Russell
  65  * @author Nakul Saraiya


 400      * @return a string describing this {@code Method}
 401      *
 402      * @jls 8.4.3 Method Modifiers
 403      * @jls 9.4   Method Declarations
 404      * @jls 9.6.1 Annotation Type Elements
 405      */
 406     public String toString() {
 407         return sharedToString(Modifier.methodModifiers(),
 408                               isDefault(),
 409                               parameterTypes,
 410                               exceptionTypes);
 411     }
 412 
 413     @Override
 414     void specificToStringHeader(StringBuilder sb) {
 415         sb.append(getReturnType().getTypeName()).append(' ');
 416         sb.append(getDeclaringClass().getTypeName()).append('.');
 417         sb.append(getName());
 418     }
 419 
 420     @Override
 421     String toShortString() {
 422         StringBuilder sb = new StringBuilder("method ");
 423         sb.append(getDeclaringClass().getTypeName()).append('.');
 424         sb.append(getName());
 425         sb.append('(');
 426         StringJoiner sj = new StringJoiner(",");
 427         for (Class<?> parameterType : getParameterTypes()) {
 428             sj.add(parameterType.getTypeName());
 429         }
 430         sb.append(sj);
 431         sb.append(')');
 432         return sb.toString();
 433     }
 434 
 435     /**
 436      * Returns a string describing this {@code Method}, including
 437      * type parameters.  The string is formatted as the method access
 438      * modifiers, if any, followed by an angle-bracketed
 439      * comma-separated list of the method's type parameters, if any,
 440      * followed by the method's generic return type, followed by a
 441      * space, followed by the class declaring the method, followed by
 442      * a period, followed by the method name, followed by a
 443      * parenthesized, comma-separated list of the method's generic
 444      * formal parameter types.
 445      *
 446      * If this method was declared to take a variable number of
 447      * arguments, instead of denoting the last parameter as
 448      * "<code><i>Type</i>[]</code>", it is denoted as
 449      * "<code><i>Type</i>...</code>".
 450      *
 451      * A space is used to separate access modifiers from one another
 452      * and from the type parameters or return type.  If there are no
 453      * type parameters, the type parameter list is elided; if the type
 454      * parameter list is present, a space separates the list from the


< prev index next >