1 /*
2 * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
113 * unknown.
114 *
115 * @author unascribed
116 * @see java.lang.ClassLoader#defineClass(byte[], int, int)
117 * @since JDK1.0
118 */
119 public final class Class<T> implements java.io.Serializable,
120 GenericDeclaration,
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 * Constructor. Only the Java Virtual Machine creates Class
134 * objects.
135 */
136 private Class() {}
137
138
139 /**
140 * Converts the object to a string. The string representation is the
141 * string "class" or "interface", followed by a space, and then by the
142 * fully qualified name of the class in the format returned by
143 * {@code getName}. If this {@code Class} object represents a
144 * primitive type, this method returns the name of the primitive type. If
145 * this {@code Class} object represents void this method returns
146 * "void".
147 *
148 * @return a string representation of this class object.
149 */
150 public String toString() {
151 return (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
152 + getName();
153 }
154
155 /**
156 * Returns a string describing this {@code Class}, including
157 * information about modifiers and type parameters.
660 * if a security manager exists and its
661 * {@code checkPermission} method denies
662 * access to the class loader for the class.
663 * @see java.lang.ClassLoader
664 * @see SecurityManager#checkPermission
665 * @see java.lang.RuntimePermission
666 */
667 @CallerSensitive
668 public ClassLoader getClassLoader() {
669 ClassLoader cl = getClassLoader0();
670 if (cl == null)
671 return null;
672 SecurityManager sm = System.getSecurityManager();
673 if (sm != null) {
674 ClassLoader.checkClassLoaderPermission(cl, Reflection.getCallerClass());
675 }
676 return cl;
677 }
678
679 // Package-private to allow ClassLoader access
680 native ClassLoader getClassLoader0();
681
682
683 /**
684 * Returns an array of {@code TypeVariable} objects that represent the
685 * type variables declared by the generic declaration represented by this
686 * {@code GenericDeclaration} object, in declaration order. Returns an
687 * array of length 0 if the underlying generic declaration declares no type
688 * variables.
689 *
690 * @return an array of {@code TypeVariable} objects that represent
691 * the type variables declared by this generic declaration
692 * @throws java.lang.reflect.GenericSignatureFormatError if the generic
693 * signature of this generic declaration does not conform to
694 * the format specified in
695 * <cite>The Java™ Virtual Machine Specification</cite>
696 * @since 1.5
697 */
698 @SuppressWarnings("unchecked")
699 public TypeVariable<Class<T>>[] getTypeParameters() {
700 ClassRepository info = getGenericInfo();
701 if (info != null)
|
1 /*
2 * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
113 * unknown.
114 *
115 * @author unascribed
116 * @see java.lang.ClassLoader#defineClass(byte[], int, int)
117 * @since JDK1.0
118 */
119 public final class Class<T> implements java.io.Serializable,
120 GenericDeclaration,
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
161 * information about modifiers and type parameters.
664 * if a security manager exists and its
665 * {@code checkPermission} method denies
666 * access to the class loader for the class.
667 * @see java.lang.ClassLoader
668 * @see SecurityManager#checkPermission
669 * @see java.lang.RuntimePermission
670 */
671 @CallerSensitive
672 public ClassLoader getClassLoader() {
673 ClassLoader cl = getClassLoader0();
674 if (cl == null)
675 return null;
676 SecurityManager sm = System.getSecurityManager();
677 if (sm != null) {
678 ClassLoader.checkClassLoaderPermission(cl, Reflection.getCallerClass());
679 }
680 return cl;
681 }
682
683 // Package-private to allow ClassLoader access
684 ClassLoader getClassLoader0() { return classLoader; }
685
686 // Initialized in JVM not by private constructor
687 private final ClassLoader classLoader;
688
689 /**
690 * Returns an array of {@code TypeVariable} objects that represent the
691 * type variables declared by the generic declaration represented by this
692 * {@code GenericDeclaration} object, in declaration order. Returns an
693 * array of length 0 if the underlying generic declaration declares no type
694 * variables.
695 *
696 * @return an array of {@code TypeVariable} objects that represent
697 * the type variables declared by this generic declaration
698 * @throws java.lang.reflect.GenericSignatureFormatError if the generic
699 * signature of this generic declaration does not conform to
700 * the format specified in
701 * <cite>The Java™ Virtual Machine Specification</cite>
702 * @since 1.5
703 */
704 @SuppressWarnings("unchecked")
705 public TypeVariable<Class<T>>[] getTypeParameters() {
706 ClassRepository info = getGenericInfo();
707 if (info != null)
|