Android examples for java.lang.reflect:Field
searches for field type in clazz and its super classes.
public class Main { /**//from w w w .java 2s .c om * searches for field type in clazz and its super classes. * * @param clazz * @param fieldName * @return type of the field if it is found else null */ public static Class<?> findFieldType(Class<?> clazz, String fieldName) { Class<?> type = clazz; while (!type.equals(Object.class)) { try { return type.getDeclaredField(fieldName).getType(); } catch (SecurityException e) { throw e; } catch (NoSuchFieldException e) { type = type.getSuperclass(); } } return null; } }