Added generics utility class for single class

This commit is contained in:
Ziver Koc 2021-03-13 16:35:54 +01:00
parent 61a703e68d
commit aa173ce092

View file

@ -122,13 +122,23 @@ public class ClassUtil {
} }
} }
/** /**
* @param field is the field to return the generics from * @param field is the field to fetch the generics classes from.
* @return the generics assigned to a specific field or a empty list * @return the generics class assigned to the specific field or a empty list if there are no generics.
*/ */
public static Class<?>[] getGenericClasses(Field field){ public static Class<?>[] getGenericClasses(Field field){
return getGenericClasses(field.getGenericType()); 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 * Traverses the class hierarchy and searches for the given super class or interface
* and returns the assigned generic types. * and returns the assigned generic types.