List of utility methods to do Reflection Field Find
Class | findFieldType(Field field, Class concreteClass) Tries to discover type of given field If the field ha a concrete type then there is nothing to do and it's type is returned. if (field.getGenericType() instanceof Class) { return field.getType(); TypeVariable[] typeParameters = field.getDeclaringClass().getTypeParameters(); for (int i = 0; i < typeParameters.length; i++) { if (typeParameters[i].getName().equals(field.getGenericType().getTypeName())) { ParameterizedType genericSuperclass = findMatchingSuperclass(concreteClass, field); if (genericSuperclass != null) { ... |
Field | findFieldWithAnnotation(String fieldName, Class> clazz, Class extends Annotation> annotationType) Look for a field based on his name and a given Annotation in a class. Field field = getField(fieldName, clazz); if (field != null && field.isAnnotationPresent(annotationType)) { return field; return null; |