Here you can find the source of findField(Class cls, String name)
Parameter | Description |
---|---|
cls | java.lang.Class |
name | String |
public static Field findField(Class cls, String name) throws NoSuchFieldException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { /**/* ww w. j a v a2s . c o m*/ * Finds the first (from the bottom of the inheritance hierarchy) field with * the specified name. Note that Class.getField returns only public fields. * * @return Field * @param cls * java.lang.Class * @param name * String */ //start extract findField public static Field findField(Class cls, String name) throws NoSuchFieldException { if (cls != null) { try { return cls.getDeclaredField(name); } catch (NoSuchFieldException e) { return findField(cls.getSuperclass(), name); } } else { throw new NoSuchFieldException(); } } }