当前位置: 首页>>代码示例>>Java>>正文


Java GenericArrayTypeImpl类代码示例

本文整理汇总了Java中sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl的典型用法代码示例。如果您正苦于以下问题:Java GenericArrayTypeImpl类的具体用法?Java GenericArrayTypeImpl怎么用?Java GenericArrayTypeImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GenericArrayTypeImpl类属于sun.reflect.generics.reflectiveObjects包,在下文中一共展示了GenericArrayTypeImpl类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolve

import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl; //导入依赖的package包/类
/**
 * Replaces the given {@code formal} type
 * with the type it stand for in this type resolver.
 *
 * @param formal  the array of types to resolve
 * @return a resolved type
 */
private Type resolve(Type formal) {
    if (formal instanceof Class) {
        return formal;
    }
    if (formal instanceof GenericArrayType) {
        Type comp = ((GenericArrayType)formal).getGenericComponentType();
        comp = resolve(comp);
        return (comp instanceof Class)
                ? Array.newInstance((Class<?>)comp, 0).getClass()
                : GenericArrayTypeImpl.make(comp);
    }
    if (formal instanceof ParameterizedType) {
        ParameterizedType fpt = (ParameterizedType)formal;
        Type[] actuals = resolve(fpt.getActualTypeArguments());
        return ParameterizedTypeImpl.make(
                (Class<?>)fpt.getRawType(), actuals, fpt.getOwnerType());
    }
    if (formal instanceof WildcardType) {
        WildcardType fwt = (WildcardType)formal;
        Type[] upper = resolve(fwt.getUpperBounds());
        Type[] lower = resolve(fwt.getLowerBounds());
        return new WildcardTypeImpl(upper, lower);
    }
    if (!(formal instanceof TypeVariable)) {
        throw new IllegalArgumentException("Bad Type kind: " + formal.getClass());
    }
    Type actual = this.map.get((TypeVariable) formal);
    if (actual == null || actual.equals(formal)) {
        return formal;
    }
    actual = fixGenericArray(actual);
    return resolve(actual);
    // A variable can be bound to another variable that is itself bound
    // to something.  For example, given:
    // class Super<T> {...}
    // class Mid<X> extends Super<T> {...}
    // class Sub extends Mid<String>
    // the variable T is bound to X, which is in turn bound to String.
    // So if we have to resolve T, we need the tail recursion here.
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:48,代码来源:TypeResolver.java


注:本文中的sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。