Here you can find the source of findField(String fieldName, Class cl)
Parameter | Description |
---|---|
fieldName | The field name to find |
cl | The class |
public static Field findField(String fieldName, Class cl)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; public class Main { /**//from w w w . j a va 2s .com * Find a field on a class. Do the lookup in the super classes of the * current class. * * @param fieldName The field name to find * @param cl The class * @return The field found, null otherwise */ public static Field findField(String fieldName, Class cl) { Class scannedClass = cl; do { try { // Retrieve the field for the current level of class and field name return scannedClass.getDeclaredField(fieldName); } catch (NoSuchFieldException | SecurityException e) { scannedClass = scannedClass.getSuperclass(); } } while (scannedClass != Object.class); return null; } }