List of utility methods to do Reflection Field Find
Field | findField(@Nonnull Class> clazz, @Nonnull String name, Class> type) find Field Class<?> searchType = clazz; while (!Object.class.equals(searchType) && searchType != null) { for (Field field : searchType.getDeclaredFields()) { if (name.equals(field.getName()) && (type == null || type.equals(field.getType()))) { return field; searchType = searchType.getSuperclass(); ... |
Field | findField(Class aClass, String aFieldName) Attempts to find a public field on the given class, searching its superclasses if necessary. try { return aClass.getField(aFieldName); } catch (NoSuchFieldException e) { return null; |
Field | findField(Class c, Class fieldtype) find Field while (c != null && c != Object.class) { for (Field field : c.getDeclaredFields()) { if (field.getType() == fieldtype) { return field; c = c.getSuperclass(); return null; |
Field | findField(Class c, String fieldName) Gets field by name, declared in the class or its superclasses. while (c != null) { for (Field f : c.getDeclaredFields()) { if (fieldName.equals(f.getName())) { f.setAccessible(true); return f; c = c.getSuperclass(); ... |
Field | findField(Class classBeFind, String name) find Field Field field = null; while (true) { try { field = classBeFind.getDeclaredField(name); } catch (Exception e) { field = null; if (field != null) { ... |
Field | findField(Class classType, String fieldName, Class fieldType) find Field for (Field field : classType.getDeclaredFields()) { if (field.getName().equals(fieldName)) { boolean isAssignableToType = (fieldType != null && field.getType().isAssignableFrom(fieldType)); boolean isPrimitiveType = (fieldType == null && field.getType().isPrimitive()); if (isAssignableToType || isPrimitiveType) { return field; return null; |
Field | findField(Class clazz, Class type, String name) find Field List<Field> fields = collectFields(clazz); for (Field each : fields) { if (name.equals(each.getName()) && (type == null || each.getType().equals(type))) return each; throw new NoSuchFieldException("Class: " + clazz + " name: " + name + " type: " + type); |
Field | findField(Class clazz, String fieldName) find Field Vector<Field> fields = new Vector<Field>(); getField(fields, clazz, fieldName); if (fields.size() == 0) { throw new RuntimeException( "ClassHelper.findField: Could not find Field with name for given Class -- ClassName: " + clazz.getName() + " -- FieldName: " + fieldName); if (fields.size() != 1) { ... |
Field | findField(Class clazz, String fieldName) find Field Field fieldToFind = null; if (clazz.getSuperclass() != null) fieldToFind = findField(clazz.getSuperclass(), fieldName); if (fieldToFind != null) return fieldToFind; for (Field field : clazz.getDeclaredFields()) { if (field.getName().equals(fieldName)) return field; ... |
AnnotatedElement | findField(Class clazz, String name) find Field return findField0(clazz, name, new StringBuilder("get").append(Character.toUpperCase(name.charAt(0))) .append(name.substring(1)).toString()); |