List of utility methods to do Reflection Field Find
Field | findField(Class> clazz, String propName) find Field Class<?> c = clazz; while (c != null) { for (Field f : c.getDeclaredFields()) { if (!f.getName().equals(propName)) { continue; int modifiers = f.getModifiers(); if (Modifier.isStatic(modifiers)) { ... |
Field | findField(Class> clazz, String targetName, Class> targetType, boolean checkInheritance, boolean strictType) find Field if (clazz == null) throw new NoSuchFieldException("No class"); if (targetName == null) throw new NoSuchFieldException("No field name"); try { Field field = clazz.getDeclaredField(targetName); if (strictType) { if (field.getType().equals(targetType)) ... |
Field | findField(Class> cls, String fieldName) Get the Field-Object for a Field specified by name. For retrieving the Field this method recursively scans super-Classes as well. Field field = null; while (field == null) { try { field = cls.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { cls = cls.getSuperclass(); if (cls.equals(Object.class)) throw e; ... |
Field | findField(Class> cls, String fieldName) Try find a field with given name. Field f = null; try { f = cls.getDeclaredField(fieldName); } catch (SecurityException ex) { } catch (NoSuchFieldException ex) { if (f != null) { return f; ... |
Field | findField(Class> cls, String fieldName) find Field Field f = null; try { f = cls.getDeclaredField(fieldName); } catch (SecurityException ex) { } catch (NoSuchFieldException ex) { if (f != null) return f; ... |
Field | findField(Class> currentClass, String fieldName) find Field while (isUserDefined(currentClass)) { try { Field f = currentClass.getDeclaredField(fieldName); if (f != null) { return f; } catch (Exception e) { } finally { ... |
Field | findField(Class> inClass, String fieldName) Finds a field by name within the given class and its super-classes. Provides private fields too. Class<?> c = inClass; while (c != null) { try { return inClass.getDeclaredField(fieldName); } catch (SecurityException e) { throw new RuntimeException( "Security does not allow to access field '" + fieldName + "' of class " + c, e); } catch (NoSuchFieldException e) { ... |
Field | findField(Class> klass, String name) find Field Field result = null; for (Class<?> iter = klass; iter != null; iter = iter.getSuperclass()) { try { result = iter.getDeclaredField(name); break; } catch (NoSuchFieldException e) { return result; |
Field | findField(Class> pClass, String fieldName) Find a field with the given name on the given class, regardless of if it is declared on the class or on of its superclasses. Field[] fields = getAllFields(pClass); for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equals(fieldName)) { return fields[i]; throw new NoSuchFieldException( "Unable to find field " + fieldName + " on class " + pClass.getCanonicalName()); ... |
Field | findField(Class> targetClass, String fieldName) find Field Field theField; try { theField = targetClass.getDeclaredField(fieldName); return accessible(theField); } catch (NoSuchFieldException e) { if (targetClass.getSuperclass() != null) return findField(targetClass.getSuperclass(), fieldName); else ... |