Here you can find the source of findField(Class> clazz, String name)
Parameter | Description |
---|---|
clazz | a parameter |
name | a parameter |
null
public static Field findField(Class<?> clazz, String name)
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2014 Xored Software Inc and others. * 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 * * Contributors://from w w w.ja va 2 s.com * Xored Software Inc - initial API and implementation and/or initial documentation *******************************************************************************/ import java.lang.reflect.Field; public class Main { /** * searches for declared field in given class and all superclasses * * @param clazz * @param name * @return {@link Field} or <code>null</code> */ public static Field findField(Class<?> clazz, String name) { if (clazz == null) { return null; } try { return clazz.getDeclaredField(name); } catch (SecurityException e) { return null; } catch (NoSuchFieldException e) { return findField(clazz.getSuperclass(), name); } } }