All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.thksystems.util.reflection.ReflectionUtils Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package de.thksystems.util.reflection;

/*
 * tksCommons
 * 
 * Author  : Thomas Kuhlmann (ThK-Systems, http://www.thk-systems.de)
 * License : LGPL (https://www.gnu.org/licenses/lgpl.html)
 */

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/** Reflection-Helper. */
public final class ReflectionUtils {

	private ReflectionUtils() {
	}

	/** Gets all fields from a class including the fields from all its super-classes. */
	public static List getAllFields(Class type) {
		List fieldList = new ArrayList<>();
		getAllFields(fieldList, type);
		return fieldList;
	}

	private static List getAllFields(List fields, Class type) {
		for (Field field : type.getDeclaredFields()) {
			fields.add(field);
		}
		if (type.getSuperclass() != null) {
			fields = getAllFields(fields, type.getSuperclass());
		}
		return fields;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy