Here you can find the source of getGenericElementType(Type type)
Map
or Collection
) specification.
Parameter | Description |
---|---|
type | generic type valued specification |
public static Type[] getGenericElementType(Type type)
//package com.java2s; //License from project: Apache License import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; public class Main { /**/*w w w. j av a2s . c om*/ * Retrieves type parameter from the parameterized type (either * <code>Map</code> or <code>Collection</code>) specification. * * @param type * generic type valued specification * @return parameter type from the provided generic specification */ public static Type[] getGenericElementType(Type type) { if (isGenericType(type)) { return ((ParameterizedType) type).getActualTypeArguments(); } return null; } /** * Checks whether the specified type is a generic type. * * @param type * type to be checked. * @return true if the type is generic, otherwise false. */ public static boolean isGenericType(Type type) { return type instanceof ParameterizedType; } }