List of utility methods to do Class Field Find
Field | findField(Class> clazz, String fieldName) Look up a field in a class and set it to accessible. StringBuilder sb = new StringBuilder(clazz.getName()); sb.append('#'); sb.append(fieldName); String fullFieldName = sb.toString(); if (fieldCache.containsKey(fullFieldName)) { Field field = fieldCache.get(fullFieldName); if (field == null) throw new NoSuchFieldError(fullFieldName); ... |
Field | findFieldRecursiveImpl(Class> clazz, String fieldName) find Field Recursive Impl try { return clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { while (true) { clazz = clazz.getSuperclass(); if (clazz == null || clazz.equals(Object.class)) break; try { ... |
Field | findFirstFieldByExactType(Class> clazz, Class> type) Returns the first field of the given type in a class. Class<?> clz = clazz; do { for (Field field : clz.getDeclaredFields()) { if (field.getType() == type) { field.setAccessible(true); return field; } while ((clz = clz.getSuperclass()) != null); throw new NoSuchFieldError("Field of type " + type.getName() + " in class " + clazz.getName()); |
Object | getAdditionalStaticField(Class> clazz, String key) get Additional Static Field return getAdditionalInstanceField(clazz, key);
|
Field[] | getFields(Class> cs) get Fields List<Field> fieldList = new ArrayList<Field>(); Class<?> c = cs; while (c != null) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { fieldList.add(field); c = c.getSuperclass(); ... |