From aa173ce092e7e8c56c89adf0c1c2593a737627c0 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sat, 13 Mar 2021 16:35:54 +0100 Subject: [PATCH] Added generics utility class for single class --- src/zutil/ClassUtil.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/zutil/ClassUtil.java b/src/zutil/ClassUtil.java index 85cec90..7247669 100755 --- a/src/zutil/ClassUtil.java +++ b/src/zutil/ClassUtil.java @@ -122,13 +122,23 @@ public class ClassUtil { } } + /** - * @param field is the field to return the generics from - * @return the generics assigned to a specific field or a empty list + * @param field is the field to fetch the generics classes from. + * @return the generics class assigned to the specific field or a empty list if there are no generics. */ public static Class[] getGenericClasses(Field field){ return getGenericClasses(field.getGenericType()); } + + /** + * @param c is the class to fetch the generics classes from. + * @return the generics class assigned to the specific class or a empty list if there are no generics. + */ + public static Class[] getGenericClasses(Class c) { + return getGenericClasses(c.getGenericSuperclass()); + } + /** * Traverses the class hierarchy and searches for the given super class or interface * and returns the assigned generic types.