Source Code : Get all fields of a class.
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Get all fields of a class.
//package org.nestframework.utils;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* Nest utility class.
*
* @author audin
*
*/
public class NestUtil {
/**
* Get all fields of a class.
*
* @param clazz The class.
* @return All fields of a class.
*/
public static Collection<Field> getFields(Class<?> clazz) {
// if (log.isDebugEnabled()) {
// log.debug("getFields(Class<?>) - start");
//}
Map<String, Field> fields = new HashMap<String, Field>();
while (clazz != null) {
for (Field field : clazz.getDeclaredFields()) {
if (!fields.containsKey(field.getName())) {
fields.put(field.getName(), field);
}
}
clazz = clazz.getSuperclass();
}
Collection<Field> returnCollection = fields.values();
// if (log.isDebugEnabled()) {
// log.debug("getFields(Class<?>) - end");
// }
return returnCollection;
}
}
Thank with us