Here you can find the source of findField(Class aClass, String aFieldName)
Parameter | Description |
---|---|
aClass | the class. |
aFieldName | the field name to search for. |
public static Field findField(Class aClass, String aFieldName)
//package com.java2s; /******************************************************************************* * Copyright 2000, 2006 Visual Systems Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License version 2 * which accompanies this distribution in a file named "COPYING". * // w w w .j a v a 2 s . c om * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *******************************************************************************/ import java.lang.reflect.Field; public class Main { /** * Attempts to find a public field on the given class, searching its superclasses if necessary. * * @param aClass the class. * @param aFieldName the field name to search for. * * @return the Field, or null if no field can be found. */ public static Field findField(Class aClass, String aFieldName) { try { return aClass.getField(aFieldName); } catch (NoSuchFieldException e) { // Ignore - return null. } return null; } }