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

Print this page




  65     private Class<T>            clazz;
  66     private int                 slot;
  67     private Class[]             parameterTypes;
  68     private Class[]             exceptionTypes;
  69     private int                 modifiers;
  70     // Generics and annotations support
  71     private transient String    signature;
  72     // generic info repository; lazily initialized
  73     private transient ConstructorRepository genericInfo;
  74     private byte[]              annotations;
  75     private byte[]              parameterAnnotations;
  76 
  77     // For non-public members or members in package-private classes,
  78     // it is necessary to perform somewhat expensive security checks.
  79     // If the security check succeeds for a given class, it will
  80     // always succeed (it is not affected by the granting or revoking
  81     // of permissions); we speed up the check in the common case by
  82     // remembering the last Class for which the check succeeded.
  83     private volatile Class securityCheckCache;
  84 
  85     // Modifiers that can be applied to a constructor in source code
  86     private static final int LANGUAGE_MODIFIERS =
  87         Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE;
  88 
  89     // Generics infrastructure
  90     // Accessor for factory
  91     private GenericsFactory getFactory() {
  92         // create scope and factory
  93         return CoreReflectionFactory.make(this, ConstructorScope.make(this));
  94     }
  95 
  96     // Accessor for generic info repository
  97     private ConstructorRepository getGenericInfo() {
  98         // lazily initialize repository if necessary
  99         if (genericInfo == null) {
 100             // create and cache generic info repository
 101             genericInfo =
 102                 ConstructorRepository.make(getSignature(),
 103                                            getFactory());
 104         }
 105         return genericInfo; //return cached repository
 106     }
 107 
 108     private volatile ConstructorAccessor constructorAccessor;


 342     }
 343 
 344     /**
 345      * Returns a string describing this {@code Constructor}.  The string is
 346      * formatted as the constructor access modifiers, if any,
 347      * followed by the fully-qualified name of the declaring class,
 348      * followed by a parenthesized, comma-separated list of the
 349      * constructor's formal parameter types.  For example:
 350      * <pre>
 351      *    public java.util.Hashtable(int,float)
 352      * </pre>
 353      *
 354      * <p>The only possible modifiers for constructors are the access
 355      * modifiers {@code public}, {@code protected} or
 356      * {@code private}.  Only one of these may appear, or none if the
 357      * constructor has default (package) access.
 358      */
 359     public String toString() {
 360         try {
 361             StringBuffer sb = new StringBuffer();
 362             int mod = getModifiers() & LANGUAGE_MODIFIERS;
 363             if (mod != 0) {
 364                 sb.append(Modifier.toString(mod) + " ");
 365             }
 366             sb.append(Field.getTypeName(getDeclaringClass()));
 367             sb.append("(");
 368             Class[] params = parameterTypes; // avoid clone
 369             for (int j = 0; j < params.length; j++) {
 370                 sb.append(Field.getTypeName(params[j]));
 371                 if (j < (params.length - 1))
 372                     sb.append(",");
 373             }
 374             sb.append(")");
 375             Class[] exceptions = exceptionTypes; // avoid clone
 376             if (exceptions.length > 0) {
 377                 sb.append(" throws ");
 378                 for (int k = 0; k < exceptions.length; k++) {
 379                     sb.append(exceptions[k].getName());
 380                     if (k < (exceptions.length - 1))
 381                         sb.append(",");
 382                 }


 406      * type parameters, the type parameter list is elided; if the type
 407      * parameter list is present, a space separates the list from the
 408      * class name.  If the constructor is declared to throw
 409      * exceptions, the parameter list is followed by a space, followed
 410      * by the word "{@code throws}" followed by a
 411      * comma-separated list of the thrown exception types.
 412      *
 413      * <p>The only possible modifiers for constructors are the access
 414      * modifiers {@code public}, {@code protected} or
 415      * {@code private}.  Only one of these may appear, or none if the
 416      * constructor has default (package) access.
 417      *
 418      * @return a string describing this {@code Constructor},
 419      * include type parameters
 420      *
 421      * @since 1.5
 422      */
 423     public String toGenericString() {
 424         try {
 425             StringBuilder sb = new StringBuilder();
 426             int mod = getModifiers() & LANGUAGE_MODIFIERS;
 427             if (mod != 0) {
 428                 sb.append(Modifier.toString(mod) + " ");
 429             }
 430             TypeVariable<?>[] typeparms = getTypeParameters();
 431             if (typeparms.length > 0) {
 432                 boolean first = true;
 433                 sb.append("<");
 434                 for(TypeVariable<?> typeparm: typeparms) {
 435                     if (!first)
 436                         sb.append(",");
 437                     // Class objects can't occur here; no need to test
 438                     // and call Class.getName().
 439                     sb.append(typeparm.toString());
 440                     first = false;
 441                 }
 442                 sb.append("> ");
 443             }
 444             sb.append(Field.getTypeName(getDeclaringClass()));
 445             sb.append("(");
 446             Type[] params = getGenericParameterTypes();




  65     private Class<T>            clazz;
  66     private int                 slot;
  67     private Class[]             parameterTypes;
  68     private Class[]             exceptionTypes;
  69     private int                 modifiers;
  70     // Generics and annotations support
  71     private transient String    signature;
  72     // generic info repository; lazily initialized
  73     private transient ConstructorRepository genericInfo;
  74     private byte[]              annotations;
  75     private byte[]              parameterAnnotations;
  76 
  77     // For non-public members or members in package-private classes,
  78     // it is necessary to perform somewhat expensive security checks.
  79     // If the security check succeeds for a given class, it will
  80     // always succeed (it is not affected by the granting or revoking
  81     // of permissions); we speed up the check in the common case by
  82     // remembering the last Class for which the check succeeded.
  83     private volatile Class securityCheckCache;
  84 




  85     // Generics infrastructure
  86     // Accessor for factory
  87     private GenericsFactory getFactory() {
  88         // create scope and factory
  89         return CoreReflectionFactory.make(this, ConstructorScope.make(this));
  90     }
  91 
  92     // Accessor for generic info repository
  93     private ConstructorRepository getGenericInfo() {
  94         // lazily initialize repository if necessary
  95         if (genericInfo == null) {
  96             // create and cache generic info repository
  97             genericInfo =
  98                 ConstructorRepository.make(getSignature(),
  99                                            getFactory());
 100         }
 101         return genericInfo; //return cached repository
 102     }
 103 
 104     private volatile ConstructorAccessor constructorAccessor;


 338     }
 339 
 340     /**
 341      * Returns a string describing this {@code Constructor}.  The string is
 342      * formatted as the constructor access modifiers, if any,
 343      * followed by the fully-qualified name of the declaring class,
 344      * followed by a parenthesized, comma-separated list of the
 345      * constructor's formal parameter types.  For example:
 346      * <pre>
 347      *    public java.util.Hashtable(int,float)
 348      * </pre>
 349      *
 350      * <p>The only possible modifiers for constructors are the access
 351      * modifiers {@code public}, {@code protected} or
 352      * {@code private}.  Only one of these may appear, or none if the
 353      * constructor has default (package) access.
 354      */
 355     public String toString() {
 356         try {
 357             StringBuffer sb = new StringBuffer();
 358             int mod = getModifiers() & Modifier.constructorModifiers();
 359             if (mod != 0) {
 360                 sb.append(Modifier.toString(mod) + " ");
 361             }
 362             sb.append(Field.getTypeName(getDeclaringClass()));
 363             sb.append("(");
 364             Class[] params = parameterTypes; // avoid clone
 365             for (int j = 0; j < params.length; j++) {
 366                 sb.append(Field.getTypeName(params[j]));
 367                 if (j < (params.length - 1))
 368                     sb.append(",");
 369             }
 370             sb.append(")");
 371             Class[] exceptions = exceptionTypes; // avoid clone
 372             if (exceptions.length > 0) {
 373                 sb.append(" throws ");
 374                 for (int k = 0; k < exceptions.length; k++) {
 375                     sb.append(exceptions[k].getName());
 376                     if (k < (exceptions.length - 1))
 377                         sb.append(",");
 378                 }


 402      * type parameters, the type parameter list is elided; if the type
 403      * parameter list is present, a space separates the list from the
 404      * class name.  If the constructor is declared to throw
 405      * exceptions, the parameter list is followed by a space, followed
 406      * by the word "{@code throws}" followed by a
 407      * comma-separated list of the thrown exception types.
 408      *
 409      * <p>The only possible modifiers for constructors are the access
 410      * modifiers {@code public}, {@code protected} or
 411      * {@code private}.  Only one of these may appear, or none if the
 412      * constructor has default (package) access.
 413      *
 414      * @return a string describing this {@code Constructor},
 415      * include type parameters
 416      *
 417      * @since 1.5
 418      */
 419     public String toGenericString() {
 420         try {
 421             StringBuilder sb = new StringBuilder();
 422             int mod = getModifiers() & Modifier.constructorModifiers();
 423             if (mod != 0) {
 424                 sb.append(Modifier.toString(mod) + " ");
 425             }
 426             TypeVariable<?>[] typeparms = getTypeParameters();
 427             if (typeparms.length > 0) {
 428                 boolean first = true;
 429                 sb.append("<");
 430                 for(TypeVariable<?> typeparm: typeparms) {
 431                     if (!first)
 432                         sb.append(",");
 433                     // Class objects can't occur here; no need to test
 434                     // and call Class.getName().
 435                     sb.append(typeparm.toString());
 436                     first = false;
 437                 }
 438                 sb.append("> ");
 439             }
 440             sb.append(Field.getTypeName(getDeclaringClass()));
 441             sb.append("(");
 442             Type[] params = getGenericParameterTypes();