class Types {

	public static Class<?> getRawType(Type type) {
		if (type instanceof Class<?>) {
			return (Class<?>) type;
		}

		if (type instanceof ParameterizedType) {
			Type rawType = ((ParameterizedType) type).getRawType();
			if (rawType instanceof Class<?>) {
				return (Class<?>) rawType;
			}
			throw new IllegalStateException(
					format("getRawType of the parameterized type %s did not return a class, but %s", type, rawType));
		}

		if (type instanceof GenericArrayType) {
			Type componentType = ((GenericArrayType) type).getGenericComponentType();
			return Array.newInstance(getRawType(componentType), 0).getClass();
		}

		throw new IllegalArgumentException(
				format("Unhandled type %s, unable to extract its raw type.", type));
	}

}