This commit is contained in:
Redkale
2018-02-08 14:41:02 +08:00
parent f9fae91c71
commit d6ba4a1ab7

View File

@@ -69,11 +69,17 @@ public abstract class TypeToken<T> {
if (type instanceof TypeVariable) {
if (declaringClass instanceof Class) {
final Class declaringClass0 = (Class) declaringClass;
final Type superType = declaringClass0.getGenericSuperclass();
Type superType = declaringClass0.getGenericSuperclass();
while (superType instanceof Class && superType != Object.class) superType = ((Class) superType).getGenericSuperclass();
if (superType instanceof ParameterizedType) {
ParameterizedType superPT = (ParameterizedType) superType;
Type[] atas = superPT.getActualTypeArguments();
TypeVariable[] asts = declaringClass0.getSuperclass().getTypeParameters();
Class ss = declaringClass0;
TypeVariable[] asts = ss.getTypeParameters();
while (atas.length != asts.length && ss != Object.class) {
ss = ss.getSuperclass();
asts = ss.getTypeParameters();
}
if (atas.length == asts.length) {
for (int i = 0; i < asts.length; i++) {
if (asts[i] == type) return atas[i];