< prev index next >

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

Print this page

 36 
 37 /**
 38  * Implementation of WildcardType interface for core reflection.
 39  */
 40 public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
 41     implements WildcardType {
 42 
 43     /*
 44      * We are required to evaluate the bounds lazily, so we store them as ASTs
 45      * until we are first asked for them.  This also neatly solves the problem
 46      * with F-bounds - you can't reify them before the formal is defined.
 47      */
 48 
 49     /** The upper bounds.  Lazily converted from FieldTypeSignature[] to Type[]. */
 50     private volatile Object[] upperBounds;
 51 
 52     /** The lower bounds.  Lazily converted from FieldTypeSignature[] to Type[]. */
 53     private volatile Object[] lowerBounds;
 54 
 55     // constructor is private to enforce access through static factory
 56     private WildcardTypeImpl(FieldTypeSignature[] ubs,
 57                              FieldTypeSignature[] lbs,
 58                              GenericsFactory f) {
 59         super(f);
 60         upperBounds = ubs;
 61         lowerBounds = lbs;
 62     }
 63 
 64     /**
 65      * Factory method.
 66      * @param ubs - an array of ASTs representing the upper bounds for the type
 67      * variable to be created
 68      * @param lbs - an array of ASTs representing the lower bounds for the type
 69      * variable to be created
 70      * @param f - a factory that can be used to manufacture reflective
 71      * objects that represent the bounds of this wildcard type
 72      * @return a wild card type with the requested bounds and factory
 73      */
 74     public static WildcardTypeImpl make(FieldTypeSignature[] ubs,
 75                                         FieldTypeSignature[] lbs,
 76                                         GenericsFactory f) {
 77         return new WildcardTypeImpl(ubs, lbs, f);
 78     }
 79 











 80     /**
 81      * Returns an array of {@code Type} objects representing the upper
 82      * bound(s) of this type variable.  Note that if no upper bound is
 83      * explicitly declared, the upper bound is {@code Object}.
 84      *
 85      * <p>For each upper bound B :
 86      * <ul>
 87      *  <li>if B is a parameterized type or a type variable, it is created,
 88      *  (see {@link #ParameterizedType} for the details of the creation
 89      *  process for parameterized types).
 90      *  <li>Otherwise, B is resolved.
 91      * </ul>
 92      *
 93      * @return an array of Types representing the upper bound(s) of this
 94      *     type variable
 95      * @throws {@code TypeNotPresentException} if any of the
 96      *     bounds refers to a non-existent type declaration
 97      * @throws {@code MalformedParameterizedTypeException} if any of the
 98      *     bounds refer to a parameterized type that cannot be instantiated
 99      *     for any reason

 36 
 37 /**
 38  * Implementation of WildcardType interface for core reflection.
 39  */
 40 public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
 41     implements WildcardType {
 42 
 43     /*
 44      * We are required to evaluate the bounds lazily, so we store them as ASTs
 45      * until we are first asked for them.  This also neatly solves the problem
 46      * with F-bounds - you can't reify them before the formal is defined.
 47      */
 48 
 49     /** The upper bounds.  Lazily converted from FieldTypeSignature[] to Type[]. */
 50     private volatile Object[] upperBounds;
 51 
 52     /** The lower bounds.  Lazily converted from FieldTypeSignature[] to Type[]. */
 53     private volatile Object[] lowerBounds;
 54 
 55     // constructor is private to enforce access through static factory
 56     private WildcardTypeImpl(Object[] ubs,
 57                              Object[] lbs,
 58                              GenericsFactory f) {
 59         super(f);
 60         upperBounds = ubs;
 61         lowerBounds = lbs;
 62     }
 63 
 64     /**
 65      * Factory method.
 66      * @param ubs - an array of ASTs representing the upper bounds for the type
 67      * variable to be created
 68      * @param lbs - an array of ASTs representing the lower bounds for the type
 69      * variable to be created
 70      * @param f - a factory that can be used to manufacture reflective
 71      * objects that represent the bounds of this wildcard type
 72      * @return a wild card type with the requested bounds and factory
 73      */
 74     public static WildcardTypeImpl make(FieldTypeSignature[] ubs,
 75                                         FieldTypeSignature[] lbs,
 76                                         GenericsFactory f) {
 77         return new WildcardTypeImpl(ubs, lbs, f);
 78     }
 79 
 80     /**
 81      * Eager factory method.
 82      * @param ubs - an array of types representing the upper bounds
 83      * @param lbs - an array of types representing the lower bounds
 84      * @return a wild card type with the requested bounds
 85      */
 86     public static WildcardTypeImpl make(Type[] ubs,
 87                                         Type[] lbs) {
 88         return new WildcardTypeImpl(ubs, lbs, null);
 89     }
 90 
 91     /**
 92      * Returns an array of {@code Type} objects representing the upper
 93      * bound(s) of this type variable.  Note that if no upper bound is
 94      * explicitly declared, the upper bound is {@code Object}.
 95      *
 96      * <p>For each upper bound B :
 97      * <ul>
 98      *  <li>if B is a parameterized type or a type variable, it is created,
 99      *  (see {@link #ParameterizedType} for the details of the creation
100      *  process for parameterized types).
101      *  <li>Otherwise, B is resolved.
102      * </ul>
103      *
104      * @return an array of Types representing the upper bound(s) of this
105      *     type variable
106      * @throws {@code TypeNotPresentException} if any of the
107      *     bounds refers to a non-existent type declaration
108      * @throws {@code MalformedParameterizedTypeException} if any of the
109      *     bounds refer to a parameterized type that cannot be instantiated
110      *     for any reason
< prev index next >