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

Print this page
rev 1343 : 6857803: Missing links to exceptions in javadoc for Class.getGeneric{Superclass, Interfaces}
Reviewed-by: chegar


 610             if (ccl != null && ccl != cl && !cl.isAncestor(ccl)) {
 611                 sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
 612             }
 613         }
 614         return cl;
 615     }
 616 
 617     // Package-private to allow ClassLoader access
 618     native ClassLoader getClassLoader0();
 619 
 620 
 621     /**
 622      * Returns an array of {@code TypeVariable} objects that represent the
 623      * type variables declared by the generic declaration represented by this
 624      * {@code GenericDeclaration} object, in declaration order.  Returns an
 625      * array of length 0 if the underlying generic declaration declares no type
 626      * variables.
 627      *
 628      * @return an array of {@code TypeVariable} objects that represent
 629      *     the type variables declared by this generic declaration
 630      * @throws GenericSignatureFormatError if the generic
 631      *     signature of this generic declaration does not conform to
 632      *     the format specified in the Java Virtual Machine Specification,
 633      *     3rd edition
 634      * @since 1.5
 635      */
 636     public TypeVariable<Class<T>>[] getTypeParameters() {
 637         if (getGenericSignature() != null)
 638             return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
 639         else
 640             return (TypeVariable<Class<T>>[])new TypeVariable[0];
 641     }
 642 
 643 
 644     /**
 645      * Returns the {@code Class} representing the superclass of the entity
 646      * (class, interface, primitive type or void) represented by this
 647      * {@code Class}.  If this {@code Class} represents either the
 648      * {@code Object} class, an interface, a primitive type, or void, then
 649      * null is returned.  If this object represents an array class then the
 650      * {@code Class} object representing the {@code Object} class is


 656 
 657 
 658     /**
 659      * Returns the {@code Type} representing the direct superclass of
 660      * the entity (class, interface, primitive type or void) represented by
 661      * this {@code Class}.
 662      *
 663      * <p>If the superclass is a parameterized type, the {@code Type}
 664      * object returned must accurately reflect the actual type
 665      * parameters used in the source code. The parameterized type
 666      * representing the superclass is created if it had not been
 667      * created before. See the declaration of {@link
 668      * java.lang.reflect.ParameterizedType ParameterizedType} for the
 669      * semantics of the creation process for parameterized types.  If
 670      * this {@code Class} represents either the {@code Object}
 671      * class, an interface, a primitive type, or void, then null is
 672      * returned.  If this object represents an array class then the
 673      * {@code Class} object representing the {@code Object} class is
 674      * returned.
 675      *
 676      * @throws GenericSignatureFormatError if the generic
 677      *     class signature does not conform to the format specified in the
 678      *     Java Virtual Machine Specification, 3rd edition
 679      * @throws TypeNotPresentException if the generic superclass
 680      *     refers to a non-existent type declaration
 681      * @throws MalformedParameterizedTypeException if the
 682      *     generic superclass refers to a parameterized type that cannot be
 683      *     instantiated  for any reason
 684      * @return the superclass of the class represented by this object
 685      * @since 1.5
 686      */
 687     public Type getGenericSuperclass() {
 688         if (getGenericSignature() != null) {
 689             // Historical irregularity:
 690             // Generic signature marks interfaces with superclass = Object
 691             // but this API returns null for interfaces
 692             if (isInterface())
 693                 return null;
 694             return getGenericInfo().getSuperclass();
 695         } else
 696             return getSuperclass();
 697     }
 698 
 699     /**
 700      * Gets the package for this class.  The class loader of this class is used
 701      * to find the package.  If the class was loaded by the bootstrap class


 778      * the array corresponds to the order of the interface names in
 779      * the {@code implements} clause of the declaration of the class
 780      * represented by this object.  In the case of an array class, the
 781      * interfaces {@code Cloneable} and {@code Serializable} are
 782      * returned in that order.
 783      *
 784      * <p>If this object represents an interface, the array contains
 785      * objects representing all interfaces directly extended by the
 786      * interface.  The order of the interface objects in the array
 787      * corresponds to the order of the interface names in the
 788      * {@code extends} clause of the declaration of the interface
 789      * represented by this object.
 790      *
 791      * <p>If this object represents a class or interface that
 792      * implements no interfaces, the method returns an array of length
 793      * 0.
 794      *
 795      * <p>If this object represents a primitive type or void, the
 796      * method returns an array of length 0.
 797      *
 798      * @throws GenericSignatureFormatError
 799      *     if the generic class signature does not conform to the format
 800      *     specified in the Java Virtual Machine Specification, 3rd edition
 801      * @throws TypeNotPresentException if any of the generic
 802      *     superinterfaces refers to a non-existent type declaration
 803      * @throws MalformedParameterizedTypeException if any of the
 804      *     generic superinterfaces refer to a parameterized type that cannot
 805      *     be instantiated  for any reason
 806      * @return an array of interfaces implemented by this class
 807      * @since 1.5
 808      */
 809     public Type[] getGenericInterfaces() {
 810         if (getGenericSignature() != null)
 811             return getGenericInfo().getSuperInterfaces();
 812         else
 813             return getInterfaces();
 814     }
 815 
 816 
 817     /**
 818      * Returns the {@code Class} representing the component type of an
 819      * array.  If this class does not represent an array class this method
 820      * returns null.
 821      *
 822      * @return the {@code Class} representing the component type of this
 823      * class if this class is an array
 824      * @see     java.lang.reflect.Array
 825      * @since JDK1.1




 610             if (ccl != null && ccl != cl && !cl.isAncestor(ccl)) {
 611                 sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
 612             }
 613         }
 614         return cl;
 615     }
 616 
 617     // Package-private to allow ClassLoader access
 618     native ClassLoader getClassLoader0();
 619 
 620 
 621     /**
 622      * Returns an array of {@code TypeVariable} objects that represent the
 623      * type variables declared by the generic declaration represented by this
 624      * {@code GenericDeclaration} object, in declaration order.  Returns an
 625      * array of length 0 if the underlying generic declaration declares no type
 626      * variables.
 627      *
 628      * @return an array of {@code TypeVariable} objects that represent
 629      *     the type variables declared by this generic declaration
 630      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 631      *     signature of this generic declaration does not conform to
 632      *     the format specified in the Java Virtual Machine Specification,
 633      *     3rd edition
 634      * @since 1.5
 635      */
 636     public TypeVariable<Class<T>>[] getTypeParameters() {
 637         if (getGenericSignature() != null)
 638             return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
 639         else
 640             return (TypeVariable<Class<T>>[])new TypeVariable[0];
 641     }
 642 
 643 
 644     /**
 645      * Returns the {@code Class} representing the superclass of the entity
 646      * (class, interface, primitive type or void) represented by this
 647      * {@code Class}.  If this {@code Class} represents either the
 648      * {@code Object} class, an interface, a primitive type, or void, then
 649      * null is returned.  If this object represents an array class then the
 650      * {@code Class} object representing the {@code Object} class is


 656 
 657 
 658     /**
 659      * Returns the {@code Type} representing the direct superclass of
 660      * the entity (class, interface, primitive type or void) represented by
 661      * this {@code Class}.
 662      *
 663      * <p>If the superclass is a parameterized type, the {@code Type}
 664      * object returned must accurately reflect the actual type
 665      * parameters used in the source code. The parameterized type
 666      * representing the superclass is created if it had not been
 667      * created before. See the declaration of {@link
 668      * java.lang.reflect.ParameterizedType ParameterizedType} for the
 669      * semantics of the creation process for parameterized types.  If
 670      * this {@code Class} represents either the {@code Object}
 671      * class, an interface, a primitive type, or void, then null is
 672      * returned.  If this object represents an array class then the
 673      * {@code Class} object representing the {@code Object} class is
 674      * returned.
 675      *
 676      * @throws java.lang.reflect.GenericSignatureFormatError if the generic
 677      *     class signature does not conform to the format specified in the
 678      *     Java Virtual Machine Specification, 3rd edition
 679      * @throws TypeNotPresentException if the generic superclass
 680      *     refers to a non-existent type declaration
 681      * @throws java.lang.reflect.MalformedParameterizedTypeException if the
 682      *     generic superclass refers to a parameterized type that cannot be
 683      *     instantiated  for any reason
 684      * @return the superclass of the class represented by this object
 685      * @since 1.5
 686      */
 687     public Type getGenericSuperclass() {
 688         if (getGenericSignature() != null) {
 689             // Historical irregularity:
 690             // Generic signature marks interfaces with superclass = Object
 691             // but this API returns null for interfaces
 692             if (isInterface())
 693                 return null;
 694             return getGenericInfo().getSuperclass();
 695         } else
 696             return getSuperclass();
 697     }
 698 
 699     /**
 700      * Gets the package for this class.  The class loader of this class is used
 701      * to find the package.  If the class was loaded by the bootstrap class


 778      * the array corresponds to the order of the interface names in
 779      * the {@code implements} clause of the declaration of the class
 780      * represented by this object.  In the case of an array class, the
 781      * interfaces {@code Cloneable} and {@code Serializable} are
 782      * returned in that order.
 783      *
 784      * <p>If this object represents an interface, the array contains
 785      * objects representing all interfaces directly extended by the
 786      * interface.  The order of the interface objects in the array
 787      * corresponds to the order of the interface names in the
 788      * {@code extends} clause of the declaration of the interface
 789      * represented by this object.
 790      *
 791      * <p>If this object represents a class or interface that
 792      * implements no interfaces, the method returns an array of length
 793      * 0.
 794      *
 795      * <p>If this object represents a primitive type or void, the
 796      * method returns an array of length 0.
 797      *
 798      * @throws java.lang.reflect.GenericSignatureFormatError
 799      *     if the generic class signature does not conform to the format
 800      *     specified in the Java Virtual Machine Specification, 3rd edition
 801      * @throws TypeNotPresentException if any of the generic
 802      *     superinterfaces refers to a non-existent type declaration
 803      * @throws java.lang.reflect.MalformedParameterizedTypeException
 804      *     if any of the generic superinterfaces refer to a parameterized
 805      *     type that cannot be instantiated for any reason
 806      * @return an array of interfaces implemented by this class
 807      * @since 1.5
 808      */
 809     public Type[] getGenericInterfaces() {
 810         if (getGenericSignature() != null)
 811             return getGenericInfo().getSuperInterfaces();
 812         else
 813             return getInterfaces();
 814     }
 815 
 816 
 817     /**
 818      * Returns the {@code Class} representing the component type of an
 819      * array.  If this class does not represent an array class this method
 820      * returns null.
 821      *
 822      * @return the {@code Class} representing the component type of this
 823      * class if this class is an array
 824      * @see     java.lang.reflect.Array
 825      * @since JDK1.1