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

Print this page




 267      * declaring class name.
 268      */
 269     public int hashCode() {
 270         return getDeclaringClass().getName().hashCode();
 271     }
 272 
 273     /**
 274      * Returns a string describing this {@code Constructor}.  The string is
 275      * formatted as the constructor access modifiers, if any,
 276      * followed by the fully-qualified name of the declaring class,
 277      * followed by a parenthesized, comma-separated list of the
 278      * constructor's formal parameter types.  For example:
 279      * <pre>
 280      *    public java.util.Hashtable(int,float)
 281      * </pre>
 282      *
 283      * <p>The only possible modifiers for constructors are the access
 284      * modifiers {@code public}, {@code protected} or
 285      * {@code private}.  Only one of these may appear, or none if the
 286      * constructor has default (package) access.



 287      */
 288     public String toString() {
 289         return sharedToString(Modifier.constructorModifiers(),

 290                               parameterTypes,
 291                               exceptionTypes);
 292     }
 293 
 294     @Override
 295     void specificToStringHeader(StringBuilder sb) {
 296         sb.append(Field.getTypeName(getDeclaringClass()));
 297     }
 298 
 299     /**
 300      * Returns a string describing this {@code Constructor},
 301      * including type parameters.  The string is formatted as the
 302      * constructor access modifiers, if any, followed by an
 303      * angle-bracketed comma separated list of the constructor's type
 304      * parameters, if any, followed by the fully-qualified name of the
 305      * declaring class, followed by a parenthesized, comma-separated
 306      * list of the constructor's generic formal parameter types.
 307      *
 308      * If this constructor was declared to take a variable number of
 309      * arguments, instead of denoting the last parameter as


 311      * "<tt><i>Type</i>...</tt>".
 312      *
 313      * A space is used to separate access modifiers from one another
 314      * and from the type parameters or return type.  If there are no
 315      * type parameters, the type parameter list is elided; if the type
 316      * parameter list is present, a space separates the list from the
 317      * class name.  If the constructor is declared to throw
 318      * exceptions, the parameter list is followed by a space, followed
 319      * by the word "{@code throws}" followed by a
 320      * comma-separated list of the thrown exception types.
 321      *
 322      * <p>The only possible modifiers for constructors are the access
 323      * modifiers {@code public}, {@code protected} or
 324      * {@code private}.  Only one of these may appear, or none if the
 325      * constructor has default (package) access.
 326      *
 327      * @return a string describing this {@code Constructor},
 328      * include type parameters
 329      *
 330      * @since 1.5

 331      */
 332     @Override
 333     public String toGenericString() {
 334         return sharedToGenericString(Modifier.constructorModifiers());
 335     }
 336 
 337     @Override
 338     void specificToGenericStringHeader(StringBuilder sb) {
 339         specificToStringHeader(sb);
 340     }
 341 
 342     /**
 343      * Uses the constructor represented by this {@code Constructor} object to
 344      * create and initialize a new instance of the constructor's
 345      * declaring class, with the specified initialization parameters.
 346      * Individual parameters are automatically unwrapped to match
 347      * primitive formal parameters, and both primitive and reference
 348      * parameters are subject to method invocation conversions as necessary.
 349      *
 350      * <p>If the number of formal parameters required by the underlying constructor
 351      * is 0, the supplied {@code initargs} array may be of length 0 or null.
 352      *
 353      * <p>If the constructor's declaring class is an inner class in a
 354      * non-static context, the first argument to the constructor needs




 267      * declaring class name.
 268      */
 269     public int hashCode() {
 270         return getDeclaringClass().getName().hashCode();
 271     }
 272 
 273     /**
 274      * Returns a string describing this {@code Constructor}.  The string is
 275      * formatted as the constructor access modifiers, if any,
 276      * followed by the fully-qualified name of the declaring class,
 277      * followed by a parenthesized, comma-separated list of the
 278      * constructor's formal parameter types.  For example:
 279      * <pre>
 280      *    public java.util.Hashtable(int,float)
 281      * </pre>
 282      *
 283      * <p>The only possible modifiers for constructors are the access
 284      * modifiers {@code public}, {@code protected} or
 285      * {@code private}.  Only one of these may appear, or none if the
 286      * constructor has default (package) access.
 287      *
 288      * @return a string describing this {@code Constructor}
 289      * @jls 8.8.3. Constructor Modifiers
 290      */
 291     public String toString() {
 292         return sharedToString(Modifier.constructorModifiers(),
 293                               false,
 294                               parameterTypes,
 295                               exceptionTypes);
 296     }
 297 
 298     @Override
 299     void specificToStringHeader(StringBuilder sb) {
 300         sb.append(Field.getTypeName(getDeclaringClass()));
 301     }
 302 
 303     /**
 304      * Returns a string describing this {@code Constructor},
 305      * including type parameters.  The string is formatted as the
 306      * constructor access modifiers, if any, followed by an
 307      * angle-bracketed comma separated list of the constructor's type
 308      * parameters, if any, followed by the fully-qualified name of the
 309      * declaring class, followed by a parenthesized, comma-separated
 310      * list of the constructor's generic formal parameter types.
 311      *
 312      * If this constructor was declared to take a variable number of
 313      * arguments, instead of denoting the last parameter as


 315      * "<tt><i>Type</i>...</tt>".
 316      *
 317      * A space is used to separate access modifiers from one another
 318      * and from the type parameters or return type.  If there are no
 319      * type parameters, the type parameter list is elided; if the type
 320      * parameter list is present, a space separates the list from the
 321      * class name.  If the constructor is declared to throw
 322      * exceptions, the parameter list is followed by a space, followed
 323      * by the word "{@code throws}" followed by a
 324      * comma-separated list of the thrown exception types.
 325      *
 326      * <p>The only possible modifiers for constructors are the access
 327      * modifiers {@code public}, {@code protected} or
 328      * {@code private}.  Only one of these may appear, or none if the
 329      * constructor has default (package) access.
 330      *
 331      * @return a string describing this {@code Constructor},
 332      * include type parameters
 333      *
 334      * @since 1.5
 335      * @jls 8.8.3. Constructor Modifiers
 336      */
 337     @Override
 338     public String toGenericString() {
 339         return sharedToGenericString(Modifier.constructorModifiers(), false);
 340     }
 341 
 342     @Override
 343     void specificToGenericStringHeader(StringBuilder sb) {
 344         specificToStringHeader(sb);
 345     }
 346 
 347     /**
 348      * Uses the constructor represented by this {@code Constructor} object to
 349      * create and initialize a new instance of the constructor's
 350      * declaring class, with the specified initialization parameters.
 351      * Individual parameters are automatically unwrapped to match
 352      * primitive formal parameters, and both primitive and reference
 353      * parameters are subject to method invocation conversions as necessary.
 354      *
 355      * <p>If the number of formal parameters required by the underlying constructor
 356      * is 0, the supplied {@code initargs} array may be of length 0 or null.
 357      *
 358      * <p>If the constructor's declaring class is an inner class in a
 359      * non-static context, the first argument to the constructor needs