Here you can find the source of findFieldRecursiveImpl(Class> clazz, String fieldName)
private static Field findFieldRecursiveImpl(Class<?> clazz, String fieldName) throws NoSuchFieldException
//package com.java2s; import java.lang.reflect.Field; public class Main { private static Field findFieldRecursiveImpl(Class<?> clazz, String fieldName) throws NoSuchFieldException { try {/*from w w w. java 2 s .co m*/ return clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { while (true) { clazz = clazz.getSuperclass(); if (clazz == null || clazz.equals(Object.class)) break; try { return clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException ignored) { } } throw e; } } }