Here you can find the source of findField(Class> clazz, String name)
public static Field findField(Class<?> clazz, String name)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014,2015 Hideki Yatomi * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ import java.lang.reflect.*; public class Main { public static Field findField(Class<?> clazz, String name) { while (clazz != null) { Field f;//w w w . j a va2 s .c o m try { f = clazz.getField(name); if (f != null) return f; } catch (NoSuchFieldException e) { // not found, try next } try { f = clazz.getDeclaredField(name); if (f != null) return f; } catch (NoSuchFieldException e) { // not found, try next } clazz = clazz.getSuperclass(); } return null; } }