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

Print this page




 121                               Type,
 122                               AnnotatedElement {
 123     private static final int ANNOTATION= 0x00002000;
 124     private static final int ENUM      = 0x00004000;
 125     private static final int SYNTHETIC = 0x00001000;
 126 
 127     private static native void registerNatives();
 128     static {
 129         registerNatives();
 130     }
 131 
 132     /*
 133      * Private constructor. Only the Java Virtual Machine creates Class objects.
 134      * This constructor is not used and prevents the default constructor being
 135      * generated.
 136      */
 137     private Class(ClassLoader loader) {
 138         // Initialize final field for classLoader.  The initialization value of non-null
 139         // prevents future JIT optimizations from assuming this final field is null.
 140         classLoader = loader;

 141     }
 142 
 143     /**
 144      * Converts the object to a string. The string representation is the
 145      * string "class" or "interface", followed by a space, and then by the
 146      * fully qualified name of the class in the format returned by
 147      * {@code getName}.  If this {@code Class} object represents a
 148      * primitive type, this method returns the name of the primitive type.  If
 149      * this {@code Class} object represents void this method returns
 150      * "void".
 151      *
 152      * @return a string representation of this class object.
 153      */
 154     public String toString() {
 155         return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
 156             + getName();
 157     }
 158 
 159     /**
 160      * Returns a string describing this {@code Class}, including


 900      *     type that cannot be instantiated for any reason
 901      * @return an array of interfaces implemented by this class
 902      * @since 1.5
 903      */
 904     public Type[] getGenericInterfaces() {
 905         ClassRepository info = getGenericInfo();
 906         return (info == null) ?  getInterfaces() : info.getSuperInterfaces();
 907     }
 908 
 909 
 910     /**
 911      * Returns the {@code Class} representing the component type of an
 912      * array.  If this class does not represent an array class this method
 913      * returns null.
 914      *
 915      * @return the {@code Class} representing the component type of this
 916      * class if this class is an array
 917      * @see     java.lang.reflect.Array
 918      * @since 1.1
 919      */
 920     public native Class<?> getComponentType();









 921 
 922 
 923     /**
 924      * Returns the Java language modifiers for this class or interface, encoded
 925      * in an integer. The modifiers consist of the Java Virtual Machine's
 926      * constants for {@code public}, {@code protected},
 927      * {@code private}, {@code final}, {@code static},
 928      * {@code abstract} and {@code interface}; they should be decoded
 929      * using the methods of class {@code Modifier}.
 930      *
 931      * <p> If the underlying class is an array class, then its
 932      * {@code public}, {@code private} and {@code protected}
 933      * modifiers are the same as those of its component type.  If this
 934      * {@code Class} represents a primitive type or void, its
 935      * {@code public} modifier is always {@code true}, and its
 936      * {@code protected} and {@code private} modifiers are always
 937      * {@code false}. If this object represents an array class, a
 938      * primitive type or void, then its {@code final} modifier is always
 939      * {@code true} and its interface modifier is always
 940      * {@code false}. The values of its other modifiers are not determined




 121                               Type,
 122                               AnnotatedElement {
 123     private static final int ANNOTATION= 0x00002000;
 124     private static final int ENUM      = 0x00004000;
 125     private static final int SYNTHETIC = 0x00001000;
 126 
 127     private static native void registerNatives();
 128     static {
 129         registerNatives();
 130     }
 131 
 132     /*
 133      * Private constructor. Only the Java Virtual Machine creates Class objects.
 134      * This constructor is not used and prevents the default constructor being
 135      * generated.
 136      */
 137     private Class(ClassLoader loader) {
 138         // Initialize final field for classLoader.  The initialization value of non-null
 139         // prevents future JIT optimizations from assuming this final field is null.
 140         classLoader = loader;
 141         componentType = null;
 142     }
 143 
 144     /**
 145      * Converts the object to a string. The string representation is the
 146      * string "class" or "interface", followed by a space, and then by the
 147      * fully qualified name of the class in the format returned by
 148      * {@code getName}.  If this {@code Class} object represents a
 149      * primitive type, this method returns the name of the primitive type.  If
 150      * this {@code Class} object represents void this method returns
 151      * "void".
 152      *
 153      * @return a string representation of this class object.
 154      */
 155     public String toString() {
 156         return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
 157             + getName();
 158     }
 159 
 160     /**
 161      * Returns a string describing this {@code Class}, including


 901      *     type that cannot be instantiated for any reason
 902      * @return an array of interfaces implemented by this class
 903      * @since 1.5
 904      */
 905     public Type[] getGenericInterfaces() {
 906         ClassRepository info = getGenericInfo();
 907         return (info == null) ?  getInterfaces() : info.getSuperInterfaces();
 908     }
 909 
 910 
 911     /**
 912      * Returns the {@code Class} representing the component type of an
 913      * array.  If this class does not represent an array class this method
 914      * returns null.
 915      *
 916      * @return the {@code Class} representing the component type of this
 917      * class if this class is an array
 918      * @see     java.lang.reflect.Array
 919      * @since 1.1
 920      */
 921     public Class<?> getComponentType() {
 922         // Only return for array types. Storage may be reused for Class for instance types.
 923         if (isArray()) {
 924             return componentType;
 925         } else {
 926             return null;
 927         }
 928     }
 929 
 930     private final Class<?> componentType;
 931 
 932 
 933     /**
 934      * Returns the Java language modifiers for this class or interface, encoded
 935      * in an integer. The modifiers consist of the Java Virtual Machine's
 936      * constants for {@code public}, {@code protected},
 937      * {@code private}, {@code final}, {@code static},
 938      * {@code abstract} and {@code interface}; they should be decoded
 939      * using the methods of class {@code Modifier}.
 940      *
 941      * <p> If the underlying class is an array class, then its
 942      * {@code public}, {@code private} and {@code protected}
 943      * modifiers are the same as those of its component type.  If this
 944      * {@code Class} represents a primitive type or void, its
 945      * {@code public} modifier is always {@code true}, and its
 946      * {@code protected} and {@code private} modifiers are always
 947      * {@code false}. If this object represents an array class, a
 948      * primitive type or void, then its {@code final} modifier is always
 949      * {@code true} and its interface modifier is always
 950      * {@code false}. The values of its other modifiers are not determined