2019-10-08 获取泛型T的Type
作者:
兣甅 | 来源:发表于
2019-10-08 21:33 被阅读0次public class BaseSubscriber<T> implements Observer<Object> {
private final Type mType;
public BaseSubscriber() {
this.mType = getSuperclassTypeParameter(getClass());
}
private Type getSuperclassTypeParameter(Class<?> subclass) {
Type superclass = subclass.getGenericSuperclass();
if (superclass instanceof Class) {
throw new RuntimeException("Missing type parameter.");
}
ParameterizedType parameterized = (ParameterizedType) superclass;
return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
}
}
本文标题:2019-10-08 获取泛型T的Type
本文链接:https://www.haomeiwen.com/subject/momipctx.html
网友评论