Package java.lang.reflect

Examples of java.lang.reflect.WildcardType


            return( o.getClass() );
        }
       
        if( type instanceof WildcardType )
        {
            WildcardType wct = (WildcardType)type;
            java.lang.reflect.Type[] upperBounds = wct.getUpperBounds();
            if (upperBounds.length >= 1)
            {
                return( getClassFromType( upperBounds[0] ) );
            }
        }
View Full Code Here


    protected Type getComponentType(Type genericType, int index) {
        if (genericType instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType)genericType;
            Type paramType = type.getActualTypeArguments()[index];
            if (paramType instanceof WildcardType) {
                WildcardType wildcardType = (WildcardType)paramType;
                // we really aren't prepared to deal with multiple upper bounds,
                // so we just look at the first one.
                return wildcardType.getUpperBounds()[0];
            } else {
                return paramType; // take our chances.
            }
        } else {
            return null;
View Full Code Here

    private Object getGenericComponent(Object genericType, int index) {
        if (genericType instanceof ParameterizedType) {
            ParameterizedType type = (ParameterizedType)genericType;

            if (type.getActualTypeArguments()[index] instanceof WildcardType) {
                WildcardType wildcardType = (WildcardType)type.getActualTypeArguments()[index];

                return wildcardType;
            } else if (type.getActualTypeArguments()[index] instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType)type.getActualTypeArguments()[index];
View Full Code Here

            ParameterizedType type = (ParameterizedType)genericType;

            if (type.getActualTypeArguments()[index] instanceof Class) {
                paramClass = (Class)type.getActualTypeArguments()[index];
            } else if (type.getActualTypeArguments()[index] instanceof WildcardType) {
                WildcardType wildcardType = (WildcardType)type.getActualTypeArguments()[index];

                if (wildcardType.getUpperBounds()[index] instanceof Class) {
                    paramClass = (Class)wildcardType.getUpperBounds()[index];
                }
            } else if (type.getActualTypeArguments()[index] instanceof ParameterizedType) {
                ParameterizedType ptype = (ParameterizedType)type.getActualTypeArguments()[index];
                paramClass = (Class)ptype.getRawType();
            }
View Full Code Here

            return Array.newInstance(componentType, 0).getClass();
        } else if (type instanceof ParameterizedType) {
            ParameterizedType pType = (ParameterizedType)type;
            return getErasure(pType.getRawType());
        } else if (type instanceof WildcardType) {
            WildcardType wType = (WildcardType)type;
            Type[] types = wType.getUpperBounds();
            if (types.length == 0) {
                return Object.class;
            }
            return getErasure(types[0]);
        } else if (type instanceof TypeVariable) {
View Full Code Here

            if (type instanceof GenericArrayType) {
                GenericArrayType arrayType = (GenericArrayType)type;
                return "[" + getSignature(arrayType.getGenericComponentType());
            }
            if (type instanceof WildcardType) {
                WildcardType wType = (WildcardType)type;
                Type[] types = wType.getUpperBounds();
                StringBuffer sb = new StringBuffer();
                if (types.length == 0 || !(types.length == 1 && types[0] == Object.class)) {
                    sb.append('+');
                    for (Type t : types) {
                        sb.append(getSignature(t));
                    }
                }
                types = wType.getLowerBounds();
                if (types.length != 0) {
                    sb.append('-');
                    for (Type t : wType.getLowerBounds()) {
                        sb.append(getSignature(t));
                    }
                }
                if (sb.length() == 0) {
                    return "*";
 
View Full Code Here

            return getErasure(arrayType.getGenericComponentType());
        } else if (type instanceof ParameterizedType) {
            ParameterizedType pType = (ParameterizedType)type;
            return getErasure(pType.getRawType());
        } else if (type instanceof WildcardType) {
            WildcardType wType = (WildcardType)type;
            Type[] types = wType.getUpperBounds();
            return getErasure(types[0]);
        } else if (type instanceof TypeVariable) {
            TypeVariable var = (TypeVariable)type;
            Type[] types = var.getBounds();
            return getErasure(types[0]);
View Full Code Here

        RepresentationConverter<Object, Object> repo = (RepresentationConverter<Object, Object>)manager.getReference(bean, paramType, cc);
        return repo;
    }

    static WildcardType createWildCard() {
        return new WildcardType() {

            @Override
            public Type[] getUpperBounds() {
                return new Type[] {Object.class};
            }
View Full Code Here

      throw new UnsupportedOperationException("Expecting parameterized type, got " + parentType
          + ".\n Are you missing the use of TypeToken idiom?\n See "
          + "http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener");
    } else if (typeToEvaluate instanceof WildcardType) {
      WildcardType castedType = (WildcardType) typeToEvaluate;
      return getActualType(castedType.getUpperBounds()[0], parentType, rawParentClass);
    } else {
      throw new IllegalArgumentException("Type \'" + typeToEvaluate + "\' is not a Class, "
          + "ParameterizedType, GenericArrayType or TypeVariable. Can't extract type.");
    }
  }
View Full Code Here

                a.append(getClassCode(t))
            }
            a.append(">;");
            return a.toString();
        } else if (type instanceof WildcardType) {
            WildcardType wt = (WildcardType)type;
            StringBuilder a = new StringBuilder();
            Type[] lowBounds = wt.getLowerBounds();
            Type[] upBounds = wt.getUpperBounds();
            for (Type t : upBounds) {
                a.append("+");
                a.append(getClassCode(t));
            }
            for (Type t : lowBounds) {
View Full Code Here

TOP

Related Classes of java.lang.reflect.WildcardType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.