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

Print this page




 325 
 326     /**
 327      * Returns a string describing this {@code Method}.  The string is
 328      * formatted as the method access modifiers, if any, followed by
 329      * the method return type, followed by a space, followed by the
 330      * class declaring the method, followed by a period, followed by
 331      * the method name, followed by a parenthesized, comma-separated
 332      * list of the method's formal parameter types. If the method
 333      * throws checked exceptions, the parameter list is followed by a
 334      * space, followed by the word throws followed by a
 335      * comma-separated list of the thrown exception types.
 336      * For example:
 337      * <pre>
 338      *    public boolean java.lang.Object.equals(java.lang.Object)
 339      * </pre>
 340      *
 341      * <p>The access modifiers are placed in canonical order as
 342      * specified by "The Java Language Specification".  This is
 343      * {@code public}, {@code protected} or {@code private} first,
 344      * and then other modifiers in the following order:
 345      * {@code abstract}, {@code static}, {@code final},
 346      * {@code synchronized}, {@code native}, {@code strictfp},
 347      * {@code default}.
 348      *
 349      * @return a string describing this {@code Method}
 350      *
 351      * @jls 8.4.3 Method Modifiers
 352      */
 353     public String toString() {
 354         return sharedToString(Modifier.methodModifiers(),
 355                               isDefault(),
 356                               parameterTypes,
 357                               exceptionTypes);
 358     }
 359 
 360     @Override
 361     void specificToStringHeader(StringBuilder sb) {
 362         sb.append(Field.getTypeName(getReturnType())).append(' ');
 363         sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 364         sb.append(getName());
 365     }
 366 
 367     /**
 368      * Returns a string describing this {@code Method}, including
 369      * type parameters.  The string is formatted as the method access
 370      * modifiers, if any, followed by an angle-bracketed
 371      * comma-separated list of the method's type parameters, if any,
 372      * followed by the method's generic return type, followed by a
 373      * space, followed by the class declaring the method, followed by
 374      * a period, followed by the method name, followed by a
 375      * parenthesized, comma-separated list of the method's generic
 376      * formal parameter types.
 377      *
 378      * If this method was declared to take a variable number of
 379      * arguments, instead of denoting the last parameter as
 380      * "<tt><i>Type</i>[]</tt>", it is denoted as
 381      * "<tt><i>Type</i>...</tt>".
 382      *
 383      * A space is used to separate access modifiers from one another
 384      * and from the type parameters or return type.  If there are no
 385      * type parameters, the type parameter list is elided; if the type
 386      * parameter list is present, a space separates the list from the
 387      * class name.  If the method is declared to throw exceptions, the
 388      * parameter list is followed by a space, followed by the word
 389      * throws followed by a comma-separated list of the generic thrown
 390      * exception types.  If there are no type parameters, the type
 391      * parameter list is elided.
 392      *
 393      * <p>The access modifiers are placed in canonical order as
 394      * specified by "The Java Language Specification".  This is
 395      * {@code public}, {@code protected} or {@code private} first,
 396      * and then other modifiers in the following order:
 397      * {@code abstract}, {@code static}, {@code final},
 398      * {@code synchronized}, {@code native}, {@code strictfp},
 399      * {@code default}.
 400      *
 401      * @return a string describing this {@code Method},
 402      * include type parameters
 403      *
 404      * @since 1.5
 405      *
 406      * @jls 8.4.3 Method Modifiers
 407      */
 408     @Override
 409     public String toGenericString() {
 410         return sharedToGenericString(Modifier.methodModifiers(), isDefault());
 411     }
 412 
 413     @Override
 414     void specificToGenericStringHeader(StringBuilder sb) {
 415         Type genRetType = getGenericReturnType();
 416         sb.append( ((genRetType instanceof Class<?>)?
 417                     Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
 418             .append(' ');
 419 
 420         sb.append(Field.getTypeName(getDeclaringClass())).append('.');
 421         sb.append(getName());
 422     }
 423 
 424     /**
 425      * Invokes the underlying method represented by this {@code Method}
 426      * object, on the specified object with the specified parameters.
 427      * Individual parameters are automatically unwrapped to match
 428      * primitive formal parameters, and both primitive and reference
 429      * parameters are subject to method invocation conversions as
 430      * necessary.
 431      *
 432      * <p>If the underlying method is static, then the specified {@code obj}
 433      * argument is ignored. It may be null.
 434      *
 435      * <p>If the number of formal parameters required by the underlying method is
 436      * 0, the supplied {@code args} array may be of length 0 or null.
 437      *
 438      * <p>If the underlying method is an instance method, it is invoked
 439      * using dynamic method lookup as documented in The Java Language
 440      * Specification, Second Edition, section 15.12.4.4; in particular,




 325 
 326     /**
 327      * Returns a string describing this {@code Method}.  The string is
 328      * formatted as the method access modifiers, if any, followed by
 329      * the method return type, followed by a space, followed by the
 330      * class declaring the method, followed by a period, followed by
 331      * the method name, followed by a parenthesized, comma-separated
 332      * list of the method's formal parameter types. If the method
 333      * throws checked exceptions, the parameter list is followed by a
 334      * space, followed by the word throws followed by a
 335      * comma-separated list of the thrown exception types.
 336      * For example:
 337      * <pre>
 338      *    public boolean java.lang.Object.equals(java.lang.Object)
 339      * </pre>
 340      *
 341      * <p>The access modifiers are placed in canonical order as
 342      * specified by "The Java Language Specification".  This is
 343      * {@code public}, {@code protected} or {@code private} first,
 344      * and then other modifiers in the following order:
 345      * {@code abstract}, {@code default}, {@code static}, {@code final},
 346      * {@code synchronized}, {@code native}, {@code strictfp}.

 347      *
 348      * @return a string describing this {@code Method}
 349      *
 350      * @jls 8.4.3 Method Modifiers
 351      */
 352     public String toString() {
 353         return sharedToString(Modifier.methodModifiers(),
 354                               isDefault(),
 355                               parameterTypes,
 356                               exceptionTypes);
 357     }
 358 
 359     @Override
 360     void specificToStringHeader(StringBuilder sb) {
 361         sb.append(getReturnType().getTypeName()).append(' ');
 362         sb.append(getDeclaringClass().getTypeName()).append('.');
 363         sb.append(getName());
 364     }
 365 
 366     /**
 367      * Returns a string describing this {@code Method}, including
 368      * type parameters.  The string is formatted as the method access
 369      * modifiers, if any, followed by an angle-bracketed
 370      * comma-separated list of the method's type parameters, if any,
 371      * followed by the method's generic return type, followed by a
 372      * space, followed by the class declaring the method, followed by
 373      * a period, followed by the method name, followed by a
 374      * parenthesized, comma-separated list of the method's generic
 375      * formal parameter types.
 376      *
 377      * If this method was declared to take a variable number of
 378      * arguments, instead of denoting the last parameter as
 379      * "<tt><i>Type</i>[]</tt>", it is denoted as
 380      * "<tt><i>Type</i>...</tt>".
 381      *
 382      * A space is used to separate access modifiers from one another
 383      * and from the type parameters or return type.  If there are no
 384      * type parameters, the type parameter list is elided; if the type
 385      * parameter list is present, a space separates the list from the
 386      * class name.  If the method is declared to throw exceptions, the
 387      * parameter list is followed by a space, followed by the word
 388      * throws followed by a comma-separated list of the generic thrown
 389      * exception types.

 390      *
 391      * <p>The access modifiers are placed in canonical order as
 392      * specified by "The Java Language Specification".  This is
 393      * {@code public}, {@code protected} or {@code private} first,
 394      * and then other modifiers in the following order:
 395      * {@code abstract}, {@code default}, {@code static}, {@code final},
 396      * {@code synchronized}, {@code native}, {@code strictfp}.

 397      *
 398      * @return a string describing this {@code Method},
 399      * include type parameters
 400      *
 401      * @since 1.5
 402      *
 403      * @jls 8.4.3 Method Modifiers
 404      */
 405     @Override
 406     public String toGenericString() {
 407         return sharedToGenericString(Modifier.methodModifiers(), isDefault());
 408     }
 409 
 410     @Override
 411     void specificToGenericStringHeader(StringBuilder sb) {
 412         Type genRetType = getGenericReturnType();
 413         sb.append(genRetType.getTypeName()).append(' ');


 414 
 415         sb.append(getDeclaringClass().getTypeName()).append('.');
 416         sb.append(getName());
 417     }
 418 
 419     /**
 420      * Invokes the underlying method represented by this {@code Method}
 421      * object, on the specified object with the specified parameters.
 422      * Individual parameters are automatically unwrapped to match
 423      * primitive formal parameters, and both primitive and reference
 424      * parameters are subject to method invocation conversions as
 425      * necessary.
 426      *
 427      * <p>If the underlying method is static, then the specified {@code obj}
 428      * argument is ignored. It may be null.
 429      *
 430      * <p>If the number of formal parameters required by the underlying method is
 431      * 0, the supplied {@code args} array may be of length 0 or null.
 432      *
 433      * <p>If the underlying method is an instance method, it is invoked
 434      * using dynamic method lookup as documented in The Java Language
 435      * Specification, Second Edition, section 15.12.4.4; in particular,