180 private Class(ClassLoader loader, Class<?> arrayComponentType) {
181 // Initialize final field for classLoader. The initialization value of non-null
182 // prevents future JIT optimizations from assuming this final field is null.
183 classLoader = loader;
184 componentType = arrayComponentType;
185 }
186
187 /**
188 * Converts the object to a string. The string representation is the
189 * string "class" or "interface", followed by a space, and then by the
190 * fully qualified name of the class in the format returned by
191 * {@code getName}. If this {@code Class} object represents a
192 * primitive type, this method returns the name of the primitive type. If
193 * this {@code Class} object represents void this method returns
194 * "void". If this {@code Class} object represents an array type,
195 * this method returns "class " followed by {@code getName}.
196 *
197 * @return a string representation of this class object.
198 */
199 public String toString() {
200 return (isValue() ? "value " : "")
201 + (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
202 + getName() + (isValue() && isBoxType() ? "/box" : "");
203 }
204
205 /**
206 * Returns a string describing this {@code Class}, including
207 * information about modifiers and type parameters.
208 *
209 * The string is formatted as a list of type modifiers, if any,
210 * followed by the kind of type (empty string for primitive types
211 * and {@code class}, {@code enum}, {@code interface}, or
212 * <code>@</code>{@code interface}, as appropriate), followed
213 * by the type's name, followed by an angle-bracketed
214 * comma-separated list of the type's type parameters, if any,
215 * including informative bounds on the type parameters, if any.
216 *
217 * A space is used to separate modifiers from one another and to
218 * separate any modifiers from the kind of type. The modifiers
219 * occur in canonical order. If there are no type parameters, the
220 * type parameter list is elided.
221 *
222 * For an array type, the string starts with the type name,
503 cl = module.getClassLoader();
504 }
505
506 if (cl != null) {
507 return cl.loadClass(module, name);
508 } else {
509 return BootLoader.loadClass(module, name);
510 }
511 }
512
513
514 /**
515 * Returns {@code true} if this class is a value class.
516 *
517 * @return {@code true} if this class is a value class.
518 */
519 public boolean isValue() {
520 int mods = this.getModifiers();
521 if ((mods & VALUE_TYPE) != 0) {
522 if ((mods & (Modifier.INTERFACE | Modifier.ABSTRACT)) != 0) {
523 throw new InternalError("value class can't have ACC_INTERFACE or ACC_ABSTRACT set");
524 }
525 if (getSuperclass() != Object.class) {
526 throw new InternalError("Super class of a value class must be java.lang.Object");
527 }
528 return true;
529 }
530 return false;
531 }
532
533 /**
534 * Returns a {@code Class} object representing the <em>box type</em>
535 * of this class if this class is a {@linkplain #isValue() value class};
536 * otherwise, returns this class.
537 *
538 * <p> A value class has two {@code Class} representations,
539 * a null-free type or a nullable box type, that can be obtained
540 * by calling {@link #asValueType()} or {@link #asBoxType()} method
541 * for conversion.
542 *
543 * @return the box type of this class if this class is a value class;
544 * otherwise, this class.
545 */
546 @HotSpotIntrinsicCandidate
620 * an interface, an array class, a primitive type, or void;
621 * or if the class has no nullary constructor;
622 * or if the instantiation fails for some other reason.
623 * @throws ExceptionInInitializerError if the initialization
624 * provoked by this method fails.
625 * @throws SecurityException
626 * If a security manager, <i>s</i>, is present and
627 * the caller's class loader is not the same as or an
628 * ancestor of the class loader for the current class and
629 * invocation of {@link SecurityManager#checkPackageAccess
630 * s.checkPackageAccess()} denies access to the package
631 * of this class.
632 */
633 @CallerSensitive
634 @Deprecated(since="9")
635 public T newInstance()
636 throws InstantiationException, IllegalAccessException
637 {
638 if (this.isValue()) {
639 throw new IllegalAccessException(
640 "cannot create new instance of value class " + this.getName());
641 }
642
643 SecurityManager sm = System.getSecurityManager();
644 if (sm != null) {
645 checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false);
646 }
647
648 // Constructor lookup
649 Constructor<T> tmpConstructor = cachedConstructor;
650 if (tmpConstructor == null) {
651 if (this == Class.class) {
652 throw new IllegalAccessException(
653 "Can not call newInstance() on the Class for java.lang.Class"
654 );
655 }
656 try {
657 Class<?>[] empty = {};
658 final Constructor<T> c = getReflectionFactory().copyConstructor(
659 getConstructor0(empty, Member.DECLARED));
660 // Disable accessibility checks on the constructor
|
180 private Class(ClassLoader loader, Class<?> arrayComponentType) {
181 // Initialize final field for classLoader. The initialization value of non-null
182 // prevents future JIT optimizations from assuming this final field is null.
183 classLoader = loader;
184 componentType = arrayComponentType;
185 }
186
187 /**
188 * Converts the object to a string. The string representation is the
189 * string "class" or "interface", followed by a space, and then by the
190 * fully qualified name of the class in the format returned by
191 * {@code getName}. If this {@code Class} object represents a
192 * primitive type, this method returns the name of the primitive type. If
193 * this {@code Class} object represents void this method returns
194 * "void". If this {@code Class} object represents an array type,
195 * this method returns "class " followed by {@code getName}.
196 *
197 * @return a string representation of this class object.
198 */
199 public String toString() {
200 return (isValue() ? "inline " : "")
201 + (isInterface() ? "interface " : (isPrimitive() ? "" : "class "))
202 + getName() + (isValue() && isBoxType() ? "?" : "");
203 }
204
205 /**
206 * Returns a string describing this {@code Class}, including
207 * information about modifiers and type parameters.
208 *
209 * The string is formatted as a list of type modifiers, if any,
210 * followed by the kind of type (empty string for primitive types
211 * and {@code class}, {@code enum}, {@code interface}, or
212 * <code>@</code>{@code interface}, as appropriate), followed
213 * by the type's name, followed by an angle-bracketed
214 * comma-separated list of the type's type parameters, if any,
215 * including informative bounds on the type parameters, if any.
216 *
217 * A space is used to separate modifiers from one another and to
218 * separate any modifiers from the kind of type. The modifiers
219 * occur in canonical order. If there are no type parameters, the
220 * type parameter list is elided.
221 *
222 * For an array type, the string starts with the type name,
503 cl = module.getClassLoader();
504 }
505
506 if (cl != null) {
507 return cl.loadClass(module, name);
508 } else {
509 return BootLoader.loadClass(module, name);
510 }
511 }
512
513
514 /**
515 * Returns {@code true} if this class is a value class.
516 *
517 * @return {@code true} if this class is a value class.
518 */
519 public boolean isValue() {
520 int mods = this.getModifiers();
521 if ((mods & VALUE_TYPE) != 0) {
522 if ((mods & (Modifier.INTERFACE | Modifier.ABSTRACT)) != 0) {
523 throw new InternalError("inline class can't have ACC_INTERFACE or ACC_ABSTRACT set");
524 }
525 if (getSuperclass() != Object.class) {
526 throw new InternalError("Super class of an inline class must be java.lang.Object");
527 }
528 return true;
529 }
530 return false;
531 }
532
533 /**
534 * Returns a {@code Class} object representing the <em>box type</em>
535 * of this class if this class is a {@linkplain #isValue() value class};
536 * otherwise, returns this class.
537 *
538 * <p> A value class has two {@code Class} representations,
539 * a null-free type or a nullable box type, that can be obtained
540 * by calling {@link #asValueType()} or {@link #asBoxType()} method
541 * for conversion.
542 *
543 * @return the box type of this class if this class is a value class;
544 * otherwise, this class.
545 */
546 @HotSpotIntrinsicCandidate
620 * an interface, an array class, a primitive type, or void;
621 * or if the class has no nullary constructor;
622 * or if the instantiation fails for some other reason.
623 * @throws ExceptionInInitializerError if the initialization
624 * provoked by this method fails.
625 * @throws SecurityException
626 * If a security manager, <i>s</i>, is present and
627 * the caller's class loader is not the same as or an
628 * ancestor of the class loader for the current class and
629 * invocation of {@link SecurityManager#checkPackageAccess
630 * s.checkPackageAccess()} denies access to the package
631 * of this class.
632 */
633 @CallerSensitive
634 @Deprecated(since="9")
635 public T newInstance()
636 throws InstantiationException, IllegalAccessException
637 {
638 if (this.isValue()) {
639 throw new IllegalAccessException(
640 "cannot create new instance of an inline class " + this.getName());
641 }
642
643 SecurityManager sm = System.getSecurityManager();
644 if (sm != null) {
645 checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false);
646 }
647
648 // Constructor lookup
649 Constructor<T> tmpConstructor = cachedConstructor;
650 if (tmpConstructor == null) {
651 if (this == Class.class) {
652 throw new IllegalAccessException(
653 "Can not call newInstance() on the Class for java.lang.Class"
654 );
655 }
656 try {
657 Class<?>[] empty = {};
658 final Constructor<T> c = getReflectionFactory().copyConstructor(
659 getConstructor0(empty, Member.DECLARED));
660 // Disable accessibility checks on the constructor
|