public static TypeClassPair getTypeArgumentAndClass(Type parameterizedType) throws IllegalArgumentException { final Type t = getTypeArgumentOfParameterizedType(parameterizedType); if (t == null) { return null; } final Class c = getClassOfType(t); if (c == null) { throw new IllegalArgumentException("Generic type not supported"); } return new TypeClassPair(t, c); }
public static TypeClassPair getTypeArgumentAndClass(Type parameterizedType) throws IllegalArgumentException { final Type t = getTypeArgumentOfParameterizedType(parameterizedType); if (t == null) { return null; } final Class c = getClassOfType(t); if (c == null) { throw new IllegalArgumentException("Generic type not supported"); } return new TypeClassPair(t, c); }
/** * Get the class that is the type argument of a parameterized type. * * @param parameterizedType must be an instance of ParameterizedType * and have exactly one type argument. * @return the class of the actual type argument. If the type argument * is a class then the class is returned. If the type argument * is a generic array type and the generic component type is a * class then class of the array is returned. if the type argument * is a parameterized type and it's raw type is a class then * that class is returned. * If the parameterizedType is not an instance of ParameterizedType * or contains more than one type argument null is returned. * @throws IllegalArgumentException if the single type argument is not of * a class, or a generic array type, or the generic component type * of the generic array type is not class, or not a parameterized * type with a raw type that is not a class. */ public static Class getGenericClass(Type parameterizedType) throws IllegalArgumentException { final Type t = getTypeArgumentOfParameterizedType(parameterizedType); if (t == null) { return null; } final Class c = getClassOfType(t); if (c == null) { throw new IllegalArgumentException("Type not supported"); } return c; }
/** * Get the class that is the type argument of a parameterized type. * * @param parameterizedType must be an instance of ParameterizedType * and have exactly one type argument. * @return the class of the actual type argument. If the type argument * is a class then the class is returned. If the type argument * is a generic array type and the generic component type is a * class then class of the array is returned. if the type argument * is a parameterized type and it's raw type is a class then * that class is returned. * If the parameterizedType is not an instance of ParameterizedType * or contains more than one type argument null is returned. * @throws IllegalArgumentException if the single type argument is not of * a class, or a generic array type, or the generic component type * of the generic array type is not class, or not a parameterized * type with a raw type that is not a class. */ public static Class getGenericClass(Type parameterizedType) throws IllegalArgumentException { final Type t = getTypeArgumentOfParameterizedType(parameterizedType); if (t == null) { return null; } final Class c = getClassOfType(t); if (c == null) { throw new IllegalArgumentException("Type not supported"); } return c; }