< prev index next >

src/java.base/share/classes/java/lang/Class.java

Print this page
rev 60127 : 8249205: Remove unnecessary trademark symbols


 396      * obtain any of the {@code Class} objects representing primitive
 397      * types or void.
 398      *
 399      * <p> If {@code name} denotes an array class, the component type of
 400      * the array class is loaded but not initialized.
 401      *
 402      * <p> For example, in an instance method the expression:
 403      *
 404      * <blockquote>
 405      *  {@code Class.forName("Foo")}
 406      * </blockquote>
 407      *
 408      * is equivalent to:
 409      *
 410      * <blockquote>
 411      *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
 412      * </blockquote>
 413      *
 414      * Note that this method throws errors related to loading, linking
 415      * or initializing as specified in Sections {@jls 12.2}, {@jls
 416      * 12.3}, and {@jls 12.4} of <cite>The Java&trade; Language
 417      * Specification</cite>.
 418      * Note that this method does not check whether the requested class
 419      * is accessible to its caller.
 420      *
 421      * @param name       fully qualified name of the desired class
 422 
 423      * @param initialize if {@code true} the class will be initialized
 424      *                   (which implies linking). See Section {@jls
 425      *                   12.4} of <cite>The Java&trade; Language
 426      *                   Specification</cite>.
 427      * @param loader     class loader from which the class must be loaded
 428      * @return           class object representing the desired class
 429      *
 430      * @throws    LinkageError if the linkage fails
 431      * @throws    ExceptionInInitializerError if the initialization provoked
 432      *            by this method fails
 433      * @throws    ClassNotFoundException if the class cannot be located by
 434      *            the specified class loader
 435      * @throws    SecurityException
 436      *            if a security manager is present, and the {@code loader} is
 437      *            {@code null}, and the caller's class loader is not
 438      *            {@code null}, and the caller does not have the
 439      *            {@link RuntimePermission}{@code ("getClassLoader")}
 440      *
 441      * @see       java.lang.Class#forName(String)
 442      * @see       java.lang.ClassLoader
 443      *
 444      * @jls 12.2 Loading of Classes and Interfaces
 445      * @jls 12.3 Linking of Classes and Interfaces


 683      * @since 1.1
 684      */
 685     @HotSpotIntrinsicCandidate
 686     public native boolean isInstance(Object obj);
 687 
 688 
 689     /**
 690      * Determines if the class or interface represented by this
 691      * {@code Class} object is either the same as, or is a superclass or
 692      * superinterface of, the class or interface represented by the specified
 693      * {@code Class} parameter. It returns {@code true} if so;
 694      * otherwise it returns {@code false}. If this {@code Class}
 695      * object represents a primitive type, this method returns
 696      * {@code true} if the specified {@code Class} parameter is
 697      * exactly this {@code Class} object; otherwise it returns
 698      * {@code false}.
 699      *
 700      * <p> Specifically, this method tests whether the type represented by the
 701      * specified {@code Class} parameter can be converted to the type
 702      * represented by this {@code Class} object via an identity conversion
 703      * or via a widening reference conversion. See <cite>The Java&trade; Language
 704      * Specification</cite>, sections {@jls 5.1.1} and {@jls 5.1.4},
 705      * for details.
 706      *
 707      * @param     cls the {@code Class} object to be checked
 708      * @return    the {@code boolean} value indicating whether objects of the
 709      *            type {@code cls} can be assigned to objects of this class
 710      * @throws    NullPointerException if the specified Class parameter is
 711      *            null.
 712      * @since     1.1
 713      */
 714     @HotSpotIntrinsicCandidate
 715     public native boolean isAssignableFrom(Class<?> cls);
 716 
 717 
 718     /**
 719      * Determines if this {@code Class} object represents an
 720      * interface type.
 721      *
 722      * @return  {@code true} if this {@code Class} object represents an interface;
 723      *          {@code false} otherwise.


 935     // Set by VM
 936     private transient Object classData;
 937 
 938     // package-private
 939     Object getClassData() {
 940         return classData;
 941     }
 942 
 943     /**
 944      * Returns an array of {@code TypeVariable} objects that represent the
 945      * type variables declared by the generic declaration represented by this
 946      * {@code GenericDeclaration} object, in declaration order.  Returns an
 947      * array of length 0 if the underlying generic declaration declares no type
 948      * variables.
 949      *
 950      * @return an array of {@code TypeVariable} objects that represent
 951      *     the type variables declared by this generic declaration
 952      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 953      *     signature of this generic declaration does not conform to
 954      *     the format specified in section {@jvms 4.7.9} of
 955      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 956      * @since 1.5
 957      */
 958     @SuppressWarnings("unchecked")
 959     public TypeVariable<Class<T>>[] getTypeParameters() {
 960         ClassRepository info = getGenericInfo();
 961         if (info != null)
 962             return (TypeVariable<Class<T>>[])info.getTypeParameters();
 963         else
 964             return (TypeVariable<Class<T>>[])new TypeVariable<?>[0];
 965     }
 966 
 967 
 968     /**
 969      * Returns the {@code Class} representing the direct superclass of the
 970      * entity (class, interface, primitive type or void) represented by
 971      * this {@code Class}.  If this {@code Class} represents either the
 972      * {@code Object} class, an interface, a primitive type, or void, then
 973      * null is returned.  If this {@code Class} object represents an array class
 974      * then the {@code Class} object representing the {@code Object} class is
 975      * returned.


 983     /**
 984      * Returns the {@code Type} representing the direct superclass of
 985      * the entity (class, interface, primitive type or void) represented by
 986      * this {@code Class} object.
 987      *
 988      * <p>If the superclass is a parameterized type, the {@code Type}
 989      * object returned must accurately reflect the actual type
 990      * arguments used in the source code. The parameterized type
 991      * representing the superclass is created if it had not been
 992      * created before. See the declaration of {@link
 993      * java.lang.reflect.ParameterizedType ParameterizedType} for the
 994      * semantics of the creation process for parameterized types.  If
 995      * this {@code Class} object represents either the {@code Object}
 996      * class, an interface, a primitive type, or void, then null is
 997      * returned.  If this {@code Class} object represents an array class
 998      * then the {@code Class} object representing the {@code Object} class is
 999      * returned.
1000      *
1001      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
1002      *     class signature does not conform to the format specified in
1003      *     section {@jvms 4.7.9} of <cite>The Java&trade; Virtual
1004      *     Machine Specification</cite>
1005      * @throws TypeNotPresentException if the generic superclass
1006      *     refers to a non-existent type declaration
1007      * @throws java.lang.reflect.MalformedParameterizedTypeException if the
1008      *     generic superclass refers to a parameterized type that cannot be
1009      *     instantiated  for any reason
1010      * @return the direct superclass of the class represented by this {@code Class} object
1011      * @since 1.5
1012      */
1013     public Type getGenericSuperclass() {
1014         ClassRepository info = getGenericInfo();
1015         if (info == null) {
1016             return getSuperclass();
1017         }
1018 
1019         // Historical irregularity:
1020         // Generic signature marks interfaces with superclass = Object
1021         // but this API returns null for interfaces
1022         if (isInterface()) {
1023             return null;


1180      *
1181      * <p>If this {@code Class} object represents an interface, the array contains objects
1182      * representing all interfaces directly extended by the interface.  The
1183      * order of the interface objects in the array corresponds to the order of
1184      * the interface names in the {@code extends} clause of the declaration of
1185      * the interface represented by this {@code Class} object.
1186      *
1187      * <p>If this {@code Class} object represents a class or interface that implements no
1188      * interfaces, the method returns an array of length 0.
1189      *
1190      * <p>If this {@code Class} object represents a primitive type or void, the method
1191      * returns an array of length 0.
1192      *
1193      * <p>If this {@code Class} object represents an array type, the
1194      * interfaces {@code Cloneable} and {@code java.io.Serializable} are
1195      * returned in that order.
1196      *
1197      * @throws java.lang.reflect.GenericSignatureFormatError
1198      *     if the generic class signature does not conform to the
1199      *     format specified in section {@jvms 4.7.9} of <cite>The
1200      *     Java&trade; Virtual Machine Specification</cite>
1201      * @throws TypeNotPresentException if any of the generic
1202      *     superinterfaces refers to a non-existent type declaration
1203      * @throws java.lang.reflect.MalformedParameterizedTypeException
1204      *     if any of the generic superinterfaces refer to a parameterized
1205      *     type that cannot be instantiated for any reason
1206      * @return an array of interfaces directly implemented by this class
1207      * @since 1.5
1208      */
1209     public Type[] getGenericInterfaces() {
1210         ClassRepository info = getGenericInfo();
1211         return (info == null) ?  getInterfaces() : info.getSuperInterfaces();
1212     }
1213 
1214 
1215     /**
1216      * Returns the {@code Class} representing the component type of an
1217      * array.  If this class does not represent an array class this method
1218      * returns null.
1219      *
1220      * @return the {@code Class} representing the component type of this


1252      * Returns the Java language modifiers for this class or interface, encoded
1253      * in an integer. The modifiers consist of the Java Virtual Machine's
1254      * constants for {@code public}, {@code protected},
1255      * {@code private}, {@code final}, {@code static},
1256      * {@code abstract} and {@code interface}; they should be decoded
1257      * using the methods of class {@code Modifier}.
1258      *
1259      * <p> If the underlying class is an array class, then its
1260      * {@code public}, {@code private} and {@code protected}
1261      * modifiers are the same as those of its component type.  If this
1262      * {@code Class} object represents a primitive type or void, its
1263      * {@code public} modifier is always {@code true}, and its
1264      * {@code protected} and {@code private} modifiers are always
1265      * {@code false}. If this {@code Class} object represents an array class, a
1266      * primitive type or void, then its {@code final} modifier is always
1267      * {@code true} and its interface modifier is always
1268      * {@code false}. The values of its other modifiers are not determined
1269      * by this specification.
1270      *
1271      * <p> The modifier encodings are defined in section {@jvms 4.1}
1272      * of <cite>The Java&trade; Virtual Machine Specification</cite>.
1273      *
1274      * @return the {@code int} representing the modifiers for this class
1275      * @see     java.lang.reflect.Modifier
1276      * @since 1.1
1277      */
1278     @HotSpotIntrinsicCandidate
1279     public native int getModifiers();
1280 
1281 
1282     /**
1283      * Gets the signers of this class.
1284      *
1285      * @return  the signers of this class, or null if there are no signers.  In
1286      *          particular, this method returns null if this {@code Class} object represents
1287      *          a primitive type or void.
1288      * @since   1.1
1289      */
1290     public native Object[] getSigners();
1291 
1292 


1661      * @return an informative string for the name of this type
1662      * @since 1.8
1663      */
1664     public String getTypeName() {
1665         if (isArray()) {
1666             try {
1667                 Class<?> cl = this;
1668                 int dimensions = 0;
1669                 do {
1670                     dimensions++;
1671                     cl = cl.getComponentType();
1672                 } while (cl.isArray());
1673                 return cl.getName() + "[]".repeat(dimensions);
1674             } catch (Throwable e) { /*FALLTHRU*/ }
1675         }
1676         return getName();
1677     }
1678 
1679     /**
1680      * Returns the canonical name of the underlying class as
1681      * defined by <cite>The Java&trade; Language Specification</cite>.
1682      * Returns {@code null} if the underlying class does not have a canonical
1683      * name. Classes without canonical names include:
1684      * <ul>
1685      * <li>a {@linkplain #isLocalClass() local class}
1686      * <li>a {@linkplain #isAnonymousClass() anonymous class}
1687      * <li>a {@linkplain #isHidden() hidden class}
1688      * <li>an array whose component type does not have a canonical name</li>
1689      * </ul>
1690      *
1691      * @return the canonical name of the underlying class if it exists, and
1692      * {@code null} otherwise.
1693      * @since 1.5
1694      */
1695     public String getCanonicalName() {
1696         ReflectionData<T> rd = reflectionData();
1697         String canonicalName = rd.canonicalName;
1698         if (canonicalName == null) {
1699             rd.canonicalName = canonicalName = getCanonicalName0();
1700         }
1701         return canonicalName == ReflectionData.NULL_SENTINEL? null : canonicalName;


2461     public Method[] getDeclaredMethods() throws SecurityException {
2462         SecurityManager sm = System.getSecurityManager();
2463         if (sm != null) {
2464             checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
2465         }
2466         return copyMethods(privateGetDeclaredMethods(false));
2467     }
2468 
2469 
2470     /**
2471      * Returns an array of {@code Constructor} objects reflecting all the
2472      * constructors declared by the class represented by this
2473      * {@code Class} object. These are public, protected, default
2474      * (package) access, and private constructors.  The elements in the array
2475      * returned are not sorted and are not in any particular order.  If the
2476      * class has a default constructor, it is included in the returned array.
2477      * This method returns an array of length 0 if this {@code Class}
2478      * object represents an interface, a primitive type, an array class, or
2479      * void.
2480      *
2481      * <p> See <cite>The Java&trade; Language Specification</cite>,
2482      * section {@jls 8.2}.
2483      *
2484      * @return  the array of {@code Constructor} objects representing all the
2485      *          declared constructors of this class
2486      * @throws  SecurityException
2487      *          If a security manager, <i>s</i>, is present and any of the
2488      *          following conditions is met:
2489      *
2490      *          <ul>
2491      *
2492      *          <li> the caller's class loader is not the same as the
2493      *          class loader of this class and invocation of
2494      *          {@link SecurityManager#checkPermission
2495      *          s.checkPermission} method with
2496      *          {@code RuntimePermission("accessDeclaredMembers")}
2497      *          denies access to the declared constructors within this class
2498      *
2499      *          <li> the caller's class loader is not the same as or an
2500      *          ancestor of the class loader for the current class and
2501      *          invocation of {@link SecurityManager#checkPackageAccess




 396      * obtain any of the {@code Class} objects representing primitive
 397      * types or void.
 398      *
 399      * <p> If {@code name} denotes an array class, the component type of
 400      * the array class is loaded but not initialized.
 401      *
 402      * <p> For example, in an instance method the expression:
 403      *
 404      * <blockquote>
 405      *  {@code Class.forName("Foo")}
 406      * </blockquote>
 407      *
 408      * is equivalent to:
 409      *
 410      * <blockquote>
 411      *  {@code Class.forName("Foo", true, this.getClass().getClassLoader())}
 412      * </blockquote>
 413      *
 414      * Note that this method throws errors related to loading, linking
 415      * or initializing as specified in Sections {@jls 12.2}, {@jls
 416      * 12.3}, and {@jls 12.4} of <cite>The Java Language
 417      * Specification</cite>.
 418      * Note that this method does not check whether the requested class
 419      * is accessible to its caller.
 420      *
 421      * @param name       fully qualified name of the desired class
 422 
 423      * @param initialize if {@code true} the class will be initialized
 424      *                   (which implies linking). See Section {@jls
 425      *                   12.4} of <cite>The Java Language
 426      *                   Specification</cite>.
 427      * @param loader     class loader from which the class must be loaded
 428      * @return           class object representing the desired class
 429      *
 430      * @throws    LinkageError if the linkage fails
 431      * @throws    ExceptionInInitializerError if the initialization provoked
 432      *            by this method fails
 433      * @throws    ClassNotFoundException if the class cannot be located by
 434      *            the specified class loader
 435      * @throws    SecurityException
 436      *            if a security manager is present, and the {@code loader} is
 437      *            {@code null}, and the caller's class loader is not
 438      *            {@code null}, and the caller does not have the
 439      *            {@link RuntimePermission}{@code ("getClassLoader")}
 440      *
 441      * @see       java.lang.Class#forName(String)
 442      * @see       java.lang.ClassLoader
 443      *
 444      * @jls 12.2 Loading of Classes and Interfaces
 445      * @jls 12.3 Linking of Classes and Interfaces


 683      * @since 1.1
 684      */
 685     @HotSpotIntrinsicCandidate
 686     public native boolean isInstance(Object obj);
 687 
 688 
 689     /**
 690      * Determines if the class or interface represented by this
 691      * {@code Class} object is either the same as, or is a superclass or
 692      * superinterface of, the class or interface represented by the specified
 693      * {@code Class} parameter. It returns {@code true} if so;
 694      * otherwise it returns {@code false}. If this {@code Class}
 695      * object represents a primitive type, this method returns
 696      * {@code true} if the specified {@code Class} parameter is
 697      * exactly this {@code Class} object; otherwise it returns
 698      * {@code false}.
 699      *
 700      * <p> Specifically, this method tests whether the type represented by the
 701      * specified {@code Class} parameter can be converted to the type
 702      * represented by this {@code Class} object via an identity conversion
 703      * or via a widening reference conversion. See <cite>The Java Language
 704      * Specification</cite>, sections {@jls 5.1.1} and {@jls 5.1.4},
 705      * for details.
 706      *
 707      * @param     cls the {@code Class} object to be checked
 708      * @return    the {@code boolean} value indicating whether objects of the
 709      *            type {@code cls} can be assigned to objects of this class
 710      * @throws    NullPointerException if the specified Class parameter is
 711      *            null.
 712      * @since     1.1
 713      */
 714     @HotSpotIntrinsicCandidate
 715     public native boolean isAssignableFrom(Class<?> cls);
 716 
 717 
 718     /**
 719      * Determines if this {@code Class} object represents an
 720      * interface type.
 721      *
 722      * @return  {@code true} if this {@code Class} object represents an interface;
 723      *          {@code false} otherwise.


 935     // Set by VM
 936     private transient Object classData;
 937 
 938     // package-private
 939     Object getClassData() {
 940         return classData;
 941     }
 942 
 943     /**
 944      * Returns an array of {@code TypeVariable} objects that represent the
 945      * type variables declared by the generic declaration represented by this
 946      * {@code GenericDeclaration} object, in declaration order.  Returns an
 947      * array of length 0 if the underlying generic declaration declares no type
 948      * variables.
 949      *
 950      * @return an array of {@code TypeVariable} objects that represent
 951      *     the type variables declared by this generic declaration
 952      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 953      *     signature of this generic declaration does not conform to
 954      *     the format specified in section {@jvms 4.7.9} of
 955      *     <cite>The Java Virtual Machine Specification</cite>
 956      * @since 1.5
 957      */
 958     @SuppressWarnings("unchecked")
 959     public TypeVariable<Class<T>>[] getTypeParameters() {
 960         ClassRepository info = getGenericInfo();
 961         if (info != null)
 962             return (TypeVariable<Class<T>>[])info.getTypeParameters();
 963         else
 964             return (TypeVariable<Class<T>>[])new TypeVariable<?>[0];
 965     }
 966 
 967 
 968     /**
 969      * Returns the {@code Class} representing the direct superclass of the
 970      * entity (class, interface, primitive type or void) represented by
 971      * this {@code Class}.  If this {@code Class} represents either the
 972      * {@code Object} class, an interface, a primitive type, or void, then
 973      * null is returned.  If this {@code Class} object represents an array class
 974      * then the {@code Class} object representing the {@code Object} class is
 975      * returned.


 983     /**
 984      * Returns the {@code Type} representing the direct superclass of
 985      * the entity (class, interface, primitive type or void) represented by
 986      * this {@code Class} object.
 987      *
 988      * <p>If the superclass is a parameterized type, the {@code Type}
 989      * object returned must accurately reflect the actual type
 990      * arguments used in the source code. The parameterized type
 991      * representing the superclass is created if it had not been
 992      * created before. See the declaration of {@link
 993      * java.lang.reflect.ParameterizedType ParameterizedType} for the
 994      * semantics of the creation process for parameterized types.  If
 995      * this {@code Class} object represents either the {@code Object}
 996      * class, an interface, a primitive type, or void, then null is
 997      * returned.  If this {@code Class} object represents an array class
 998      * then the {@code Class} object representing the {@code Object} class is
 999      * returned.
1000      *
1001      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
1002      *     class signature does not conform to the format specified in
1003      *     section {@jvms 4.7.9} of <cite>The Java Virtual
1004      *     Machine Specification</cite>
1005      * @throws TypeNotPresentException if the generic superclass
1006      *     refers to a non-existent type declaration
1007      * @throws java.lang.reflect.MalformedParameterizedTypeException if the
1008      *     generic superclass refers to a parameterized type that cannot be
1009      *     instantiated  for any reason
1010      * @return the direct superclass of the class represented by this {@code Class} object
1011      * @since 1.5
1012      */
1013     public Type getGenericSuperclass() {
1014         ClassRepository info = getGenericInfo();
1015         if (info == null) {
1016             return getSuperclass();
1017         }
1018 
1019         // Historical irregularity:
1020         // Generic signature marks interfaces with superclass = Object
1021         // but this API returns null for interfaces
1022         if (isInterface()) {
1023             return null;


1180      *
1181      * <p>If this {@code Class} object represents an interface, the array contains objects
1182      * representing all interfaces directly extended by the interface.  The
1183      * order of the interface objects in the array corresponds to the order of
1184      * the interface names in the {@code extends} clause of the declaration of
1185      * the interface represented by this {@code Class} object.
1186      *
1187      * <p>If this {@code Class} object represents a class or interface that implements no
1188      * interfaces, the method returns an array of length 0.
1189      *
1190      * <p>If this {@code Class} object represents a primitive type or void, the method
1191      * returns an array of length 0.
1192      *
1193      * <p>If this {@code Class} object represents an array type, the
1194      * interfaces {@code Cloneable} and {@code java.io.Serializable} are
1195      * returned in that order.
1196      *
1197      * @throws java.lang.reflect.GenericSignatureFormatError
1198      *     if the generic class signature does not conform to the
1199      *     format specified in section {@jvms 4.7.9} of <cite>The
1200      *     Java Virtual Machine Specification</cite>
1201      * @throws TypeNotPresentException if any of the generic
1202      *     superinterfaces refers to a non-existent type declaration
1203      * @throws java.lang.reflect.MalformedParameterizedTypeException
1204      *     if any of the generic superinterfaces refer to a parameterized
1205      *     type that cannot be instantiated for any reason
1206      * @return an array of interfaces directly implemented by this class
1207      * @since 1.5
1208      */
1209     public Type[] getGenericInterfaces() {
1210         ClassRepository info = getGenericInfo();
1211         return (info == null) ?  getInterfaces() : info.getSuperInterfaces();
1212     }
1213 
1214 
1215     /**
1216      * Returns the {@code Class} representing the component type of an
1217      * array.  If this class does not represent an array class this method
1218      * returns null.
1219      *
1220      * @return the {@code Class} representing the component type of this


1252      * Returns the Java language modifiers for this class or interface, encoded
1253      * in an integer. The modifiers consist of the Java Virtual Machine's
1254      * constants for {@code public}, {@code protected},
1255      * {@code private}, {@code final}, {@code static},
1256      * {@code abstract} and {@code interface}; they should be decoded
1257      * using the methods of class {@code Modifier}.
1258      *
1259      * <p> If the underlying class is an array class, then its
1260      * {@code public}, {@code private} and {@code protected}
1261      * modifiers are the same as those of its component type.  If this
1262      * {@code Class} object represents a primitive type or void, its
1263      * {@code public} modifier is always {@code true}, and its
1264      * {@code protected} and {@code private} modifiers are always
1265      * {@code false}. If this {@code Class} object represents an array class, a
1266      * primitive type or void, then its {@code final} modifier is always
1267      * {@code true} and its interface modifier is always
1268      * {@code false}. The values of its other modifiers are not determined
1269      * by this specification.
1270      *
1271      * <p> The modifier encodings are defined in section {@jvms 4.1}
1272      * of <cite>The Java Virtual Machine Specification</cite>.
1273      *
1274      * @return the {@code int} representing the modifiers for this class
1275      * @see     java.lang.reflect.Modifier
1276      * @since 1.1
1277      */
1278     @HotSpotIntrinsicCandidate
1279     public native int getModifiers();
1280 
1281 
1282     /**
1283      * Gets the signers of this class.
1284      *
1285      * @return  the signers of this class, or null if there are no signers.  In
1286      *          particular, this method returns null if this {@code Class} object represents
1287      *          a primitive type or void.
1288      * @since   1.1
1289      */
1290     public native Object[] getSigners();
1291 
1292 


1661      * @return an informative string for the name of this type
1662      * @since 1.8
1663      */
1664     public String getTypeName() {
1665         if (isArray()) {
1666             try {
1667                 Class<?> cl = this;
1668                 int dimensions = 0;
1669                 do {
1670                     dimensions++;
1671                     cl = cl.getComponentType();
1672                 } while (cl.isArray());
1673                 return cl.getName() + "[]".repeat(dimensions);
1674             } catch (Throwable e) { /*FALLTHRU*/ }
1675         }
1676         return getName();
1677     }
1678 
1679     /**
1680      * Returns the canonical name of the underlying class as
1681      * defined by <cite>The Java Language Specification</cite>.
1682      * Returns {@code null} if the underlying class does not have a canonical
1683      * name. Classes without canonical names include:
1684      * <ul>
1685      * <li>a {@linkplain #isLocalClass() local class}
1686      * <li>a {@linkplain #isAnonymousClass() anonymous class}
1687      * <li>a {@linkplain #isHidden() hidden class}
1688      * <li>an array whose component type does not have a canonical name</li>
1689      * </ul>
1690      *
1691      * @return the canonical name of the underlying class if it exists, and
1692      * {@code null} otherwise.
1693      * @since 1.5
1694      */
1695     public String getCanonicalName() {
1696         ReflectionData<T> rd = reflectionData();
1697         String canonicalName = rd.canonicalName;
1698         if (canonicalName == null) {
1699             rd.canonicalName = canonicalName = getCanonicalName0();
1700         }
1701         return canonicalName == ReflectionData.NULL_SENTINEL? null : canonicalName;


2461     public Method[] getDeclaredMethods() throws SecurityException {
2462         SecurityManager sm = System.getSecurityManager();
2463         if (sm != null) {
2464             checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true);
2465         }
2466         return copyMethods(privateGetDeclaredMethods(false));
2467     }
2468 
2469 
2470     /**
2471      * Returns an array of {@code Constructor} objects reflecting all the
2472      * constructors declared by the class represented by this
2473      * {@code Class} object. These are public, protected, default
2474      * (package) access, and private constructors.  The elements in the array
2475      * returned are not sorted and are not in any particular order.  If the
2476      * class has a default constructor, it is included in the returned array.
2477      * This method returns an array of length 0 if this {@code Class}
2478      * object represents an interface, a primitive type, an array class, or
2479      * void.
2480      *
2481      * <p> See <cite>The Java Language Specification</cite>,
2482      * section {@jls 8.2}.
2483      *
2484      * @return  the array of {@code Constructor} objects representing all the
2485      *          declared constructors of this class
2486      * @throws  SecurityException
2487      *          If a security manager, <i>s</i>, is present and any of the
2488      *          following conditions is met:
2489      *
2490      *          <ul>
2491      *
2492      *          <li> the caller's class loader is not the same as the
2493      *          class loader of this class and invocation of
2494      *          {@link SecurityManager#checkPermission
2495      *          s.checkPermission} method with
2496      *          {@code RuntimePermission("accessDeclaredMembers")}
2497      *          denies access to the declared constructors within this class
2498      *
2499      *          <li> the caller's class loader is not the same as or an
2500      *          ancestor of the class loader for the current class and
2501      *          invocation of {@link SecurityManager#checkPackageAccess


< prev index next >