泛型检查
/**
*
* object may be declared as:
* HttpResultSubscriber objectSub = new HttpResultSubscriber<String>(){}
* then object will be objectSub and clz will be String.class
* call checkGenericType(objectSub, String.class)
* @param object
* @param clz
* @return
*/
private boolean checkGenericType(Object object, Class<?> clz) {
Type superclass = object.getClass().getGenericSuperclass();
ParameterizedType parameterized = (ParameterizedType) superclass;
Type type = parameterized.getActualTypeArguments()[0];
if (type instanceof Class<?> && ((Class<?>) type).isAssignableFrom(clz)) {
return true;
}
return false;
}