diff --git a/concept-domain/concept-domain-core/src/main/java/com/github/linyuzai/domain/core/link/DomainLink.java b/concept-domain/concept-domain-core/src/main/java/com/github/linyuzai/domain/core/link/DomainLink.java index 6c3a4e849..7017b5a67 100644 --- a/concept-domain/concept-domain-core/src/main/java/com/github/linyuzai/domain/core/link/DomainLink.java +++ b/concept-domain/concept-domain-core/src/main/java/com/github/linyuzai/domain/core/link/DomainLink.java @@ -39,17 +39,9 @@ public static Class generic(Class target, int index) { if (type instanceof ParameterizedType) { Type[] types = ((ParameterizedType) type).getActualTypeArguments(); Type t = types[index]; - if (t instanceof Class) { - return (Class) t; - } - if (t instanceof TypeVariable) { - Type[] bounds = ((TypeVariable) t).getBounds(); - if (bounds.length > 0) { - Type bound = bounds[0]; - if (bound instanceof Class) { - return (Class) bound; - } - } + Class classForType = getClassForType(t); + if (classForType != null) { + return classForType; } } throw new DomainException("Can not get generic type"); @@ -64,7 +56,8 @@ public static Class collection(Class classForType = getClassForType(pt.getRawType()); + if (classForType != null && DomainCollection.class.isAssignableFrom(classForType)) { Type[] arguments = pt.getActualTypeArguments(); return arguments[0]; } @@ -92,4 +85,21 @@ public static Class collection(Class Class getClassForType(Type type) { + if (type instanceof Class) { + return (Class) type; + } + if (type instanceof ParameterizedType) { + return getClassForType(((ParameterizedType) type).getRawType()); + } + if (type instanceof TypeVariable) { + Type[] bounds = ((TypeVariable) type).getBounds(); + if (bounds.length > 0) { + Type bound = bounds[0]; + return getClassForType(bound); + } + } + return null; + } }