< prev index next >

src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/ParameterizedTypeImpl.java

Print this page




  56         // check correct arity of actual type args
  57         if (formals.length != actualTypeArguments.length){
  58             throw new MalformedParameterizedTypeException();
  59         }
  60         for (int i = 0; i < actualTypeArguments.length; i++) {
  61             // check actuals against formals' bounds
  62         }
  63     }
  64 
  65     /**
  66      * Static factory. Given a (generic) class, actual type arguments
  67      * and an owner type, creates a parameterized type.
  68      * This class can be instantiated with a a raw type that does not
  69      * represent a generic type, provided the list of actual type
  70      * arguments is empty.
  71      * If the ownerType argument is null, the declaring class of the
  72      * raw type is used as the owner type.
  73      * <p> This method throws a MalformedParameterizedTypeException
  74      * under the following circumstances:
  75      * If the number of actual type arguments (i.e., the size of the
  76      * array <tt>typeArgs</tt>) does not correspond to the number of
  77      * formal type arguments.
  78      * If any of the actual type arguments is not an instance of the
  79      * bounds on the corresponding formal.
  80      * @param rawType the Class representing the generic type declaration being
  81      * instantiated
  82      * @param actualTypeArguments - a (possibly empty) array of types
  83      * representing the actual type arguments to the parameterized type
  84      * @param ownerType - the enclosing type, if known.
  85      * @return An instance of <tt>ParameterizedType</tt>
  86      * @throws MalformedParameterizedTypeException - if the instantiation
  87      * is invalid
  88      */
  89     public static ParameterizedTypeImpl make(Class<?> rawType,
  90                                              Type[] actualTypeArguments,
  91                                              Type ownerType) {
  92         return new ParameterizedTypeImpl(rawType, actualTypeArguments,
  93                                          ownerType);
  94     }
  95 
  96 
  97     /**
  98      * Returns an array of <tt>Type</tt> objects representing the actual type
  99      * arguments to this type.
 100      *
 101      * <p>Note that in some cases, the returned array be empty. This can occur
 102      * if this type represents a non-parameterized type nested within
 103      * a parameterized type.
 104      *
 105      * @return an array of <tt>Type</tt> objects representing the actual type
 106      *     arguments to this type
 107      * @throws <tt>TypeNotPresentException</tt> if any of the
 108      *     actual type arguments refers to a non-existent type declaration
 109      * @throws <tt>MalformedParameterizedTypeException</tt> if any of the
 110      *     actual type parameters refer to a parameterized type that cannot
 111      *     be instantiated for any reason
 112      * @since 1.5
 113      */
 114     public Type[] getActualTypeArguments() {
 115         return actualTypeArguments.clone();
 116     }
 117 
 118     /**
 119      * Returns the <tt>Type</tt> object representing the class or interface
 120      * that declared this type.
 121      *
 122      * @return the <tt>Type</tt> object representing the class or interface
 123      *     that declared this type
 124      */
 125     public Class<?> getRawType() {
 126         return rawType;
 127     }
 128 
 129 
 130     /**
 131      * Returns a <tt>Type</tt> object representing the type that this type
 132      * is a member of.  For example, if this type is <tt>O<T>.I<S></tt>,
 133      * return a representation of <tt>O<T></tt>.
 134      *
 135      * <p>If this type is a top-level type, <tt>null</tt> is returned.
 136      *
 137      * @return a <tt>Type</tt> object representing the type that
 138      *     this type is a member of. If this type is a top-level type,
 139      *     <tt>null</tt> is returned
 140      * @throws <tt>TypeNotPresentException</tt> if the owner type
 141      *     refers to a non-existent type declaration
 142      * @throws <tt>MalformedParameterizedTypeException</tt> if the owner type
 143      *     refers to a parameterized type that cannot be instantiated
 144      *     for any reason
 145      *
 146      */
 147     public Type getOwnerType() {
 148         return ownerType;
 149     }
 150 
 151     /*
 152      * From the JavaDoc for java.lang.reflect.ParameterizedType
 153      * "Instances of classes that implement this interface must
 154      * implement an equals() method that equates any two instances
 155      * that share the same generic type declaration and have equal
 156      * type parameters."
 157      */
 158     @Override
 159     public boolean equals(Object o) {
 160         if (o instanceof ParameterizedType) {
 161             // Check that information is equivalent
 162             ParameterizedType that = (ParameterizedType) o;




  56         // check correct arity of actual type args
  57         if (formals.length != actualTypeArguments.length){
  58             throw new MalformedParameterizedTypeException();
  59         }
  60         for (int i = 0; i < actualTypeArguments.length; i++) {
  61             // check actuals against formals' bounds
  62         }
  63     }
  64 
  65     /**
  66      * Static factory. Given a (generic) class, actual type arguments
  67      * and an owner type, creates a parameterized type.
  68      * This class can be instantiated with a a raw type that does not
  69      * represent a generic type, provided the list of actual type
  70      * arguments is empty.
  71      * If the ownerType argument is null, the declaring class of the
  72      * raw type is used as the owner type.
  73      * <p> This method throws a MalformedParameterizedTypeException
  74      * under the following circumstances:
  75      * If the number of actual type arguments (i.e., the size of the
  76      * array {@code typeArgs}) does not correspond to the number of
  77      * formal type arguments.
  78      * If any of the actual type arguments is not an instance of the
  79      * bounds on the corresponding formal.
  80      * @param rawType the Class representing the generic type declaration being
  81      * instantiated
  82      * @param actualTypeArguments a (possibly empty) array of types
  83      * representing the actual type arguments to the parameterized type
  84      * @param ownerType the enclosing type, if known.
  85      * @return An instance of {@code ParameterizedType}
  86      * @throws MalformedParameterizedTypeException if the instantiation
  87      * is invalid
  88      */
  89     public static ParameterizedTypeImpl make(Class<?> rawType,
  90                                              Type[] actualTypeArguments,
  91                                              Type ownerType) {
  92         return new ParameterizedTypeImpl(rawType, actualTypeArguments,
  93                                          ownerType);
  94     }
  95 
  96 
  97     /**
  98      * Returns an array of {@code Type} objects representing the actual type
  99      * arguments to this type.
 100      *
 101      * <p>Note that in some cases, the returned array be empty. This can occur
 102      * if this type represents a non-parameterized type nested within
 103      * a parameterized type.
 104      *
 105      * @return an array of {@code Type} objects representing the actual type
 106      *     arguments to this type
 107      * @throws TypeNotPresentException if any of the
 108      *     actual type arguments refers to a non-existent type declaration
 109      * @throws MalformedParameterizedTypeException if any of the
 110      *     actual type parameters refer to a parameterized type that cannot
 111      *     be instantiated for any reason
 112      * @since 1.5
 113      */
 114     public Type[] getActualTypeArguments() {
 115         return actualTypeArguments.clone();
 116     }
 117 
 118     /**
 119      * Returns the {@code Type} object representing the class or interface
 120      * that declared this type.
 121      *
 122      * @return the {@code Type} object representing the class or interface
 123      *     that declared this type
 124      */
 125     public Class<?> getRawType() {
 126         return rawType;
 127     }
 128 
 129 
 130     /**
 131      * Returns a {@code Type} object representing the type that this type
 132      * is a member of.  For example, if this type is {@code O<T>.I<S>},
 133      * return a representation of {@code O<T>}.
 134      *
 135      * <p>If this type is a top-level type, {@code null} is returned.
 136      *
 137      * @return a {@code Type} object representing the type that
 138      *     this type is a member of. If this type is a top-level type,
 139      *     {@code null} is returned
 140      * @throws TypeNotPresentException if the owner type
 141      *     refers to a non-existent type declaration
 142      * @throws MalformedParameterizedTypeException if the owner type
 143      *     refers to a parameterized type that cannot be instantiated
 144      *     for any reason
 145      *
 146      */
 147     public Type getOwnerType() {
 148         return ownerType;
 149     }
 150 
 151     /*
 152      * From the JavaDoc for java.lang.reflect.ParameterizedType
 153      * "Instances of classes that implement this interface must
 154      * implement an equals() method that equates any two instances
 155      * that share the same generic type declaration and have equal
 156      * type parameters."
 157      */
 158     @Override
 159     public boolean equals(Object o) {
 160         if (o instanceof ParameterizedType) {
 161             // Check that information is equivalent
 162             ParameterizedType that = (ParameterizedType) o;


< prev index next >