/** * Returns a two element array containing this map's key and value types in positions 0 and 1 * respectively. */ static Type[] mapKeyAndValueTypes(Type context, Class<?> contextRawType) { // Work around a problem with the declaration of java.util.Properties. That class should extend // Hashtable<String, String>, but it's declared to extend Hashtable<Object, Object>. if (context == Properties.class) return new Type[] { String.class, String.class }; Type mapType = getSupertype(context, contextRawType, Map.class); if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type collectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType) collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }
/** * Returns a two element array containing this map's key and value types in positions 0 and 1 * respectively. */ static Type[] mapKeyAndValueTypes(Type context, Class<?> contextRawType) { // Work around a problem with the declaration of java.util.Properties. That class should extend // Hashtable<String, String>, but it's declared to extend Hashtable<Object, Object>. if (context == Properties.class) return new Type[] { String.class, String.class }; Type mapType = getSupertype(context, contextRawType, Map.class); if (mapType instanceof ParameterizedType) { ParameterizedType mapParameterizedType = (ParameterizedType) mapType; return mapParameterizedType.getActualTypeArguments(); } return new Type[] { Object.class, Object.class }; }
/** * Returns the element type of this collection type. * @throws IllegalArgumentException if this type is not a collection. */ public static Type collectionElementType(Type context, Class<?> contextRawType) { Type collectionType = getSupertype(context, contextRawType, Collection.class); if (collectionType instanceof WildcardType) { collectionType = ((WildcardType) collectionType).getUpperBounds()[0]; } if (collectionType instanceof ParameterizedType) { return ((ParameterizedType) collectionType).getActualTypeArguments()[0]; } return Object.class; }