@Test public void testGetRawClass() { assertEquals(ParametrizedClass.class, getRawClass(ParametrizedClass.class)); assertEquals(Object.class, getRawClass(((ParameterizedType) new GenericType<List<?>>() { }.getType()).getActualTypeArguments()[0])); assertEquals(Integer.class, getRawClass(((ParameterizedType) new GenericType<List<Integer>>() { }.getType()).getActualTypeArguments()[0])); Type typeVar = ((ParameterizedType) tListF).getActualTypeArguments()[0]; assertEquals(Object.class, getRawClass(typeVar)); typeVar = ((ParameterizedType) tListE).getActualTypeArguments()[0]; assertEquals(Number.class, getRawClass(typeVar)); }
public final static Class<?> getRawClass(Type type) { if (type instanceof Class<?>) return (Class<?>) type; else if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return (Class<?>) pType.getRawType(); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawClass(componentType), 0).getClass(); } else return getRawClass(expand(type, null)); }
TypeUtil { public final static Class<?> getRawClass(Type type) { if (type instanceof Class<?>) return (Class<?>) type; else if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return (Class<?>) pType.getRawType(); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawClass(componentType), 0).getClass(); } else return getRawClass(expand(type, null)); } }
TypeUtil { public final static Class<?> getRawClass(Type type) { if (type instanceof Class<?>) return (Class<?>) type; else if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return (Class<?>) pType.getRawType(); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawClass(componentType), 0).getClass(); } else return getRawClass(expand(type, null)); }  }
TypeUtil { public final static Class<?> getRawClass(Type type) { if (type instanceof Class<?>) return (Class<?>) type; else if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return (Class<?>) pType.getRawType(); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawClass(componentType), 0).getClass(); } else return getRawClass(expand(type, null)); }  final static Class<?> wrap(Class<?> clazz); final static Type expandType(final Type type, final Type rootType); final static Type lookupGenericType(Class<?> ofClass, Class<?> inClass); final static Class<?> getRawClass(Type type); final static Type getCollectionType(Type type); final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass); final static boolean match(Type type, Type oType, boolean strictMatch); final static Type typeOf(int parameterIdx, Type fromType); }
TypeUtil { public final static Class<?> getRawClass(Type type) { if (type instanceof Class<?>) return (Class<?>) type; else if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return (Class<?>) pType.getRawType(); } else if (type instanceof GenericArrayType) { Type componentType = ((GenericArrayType) type).getGenericComponentType(); return Array.newInstance(getRawClass(componentType), 0).getClass(); } else return getRawClass(expand(type, null)); }  final static Class<?> wrap(Class<?> clazz); final static Type expandType(final Type type, final Type rootType); final static Type lookupGenericType(Class<?> ofClass, Class<?> inClass); final static Class<?> getRawClass(Type type); final static Type getCollectionType(Type type); final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass); final static boolean match(Type type, Type oType, boolean strictMatch); final static Type typeOf(int parameterIdx, Type fromType);  }