Source Code : All Fields Snippet
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
All Fields Snippet
/*
Java Reflection in Action
Ira R. Forman and Nate Forman
ISBN 1932394184
Publisher: Manning Publications Co.
*/
import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.List;
public class AllFieldsSnippet {
public static void main(String[] args) {
Object obj = new Object();
//start extract AllFieldsSnippet
Class cls = obj.getClass();
List accum = new LinkedList();
while (cls != null) {
Field[] f = cls.getDeclaredFields();
for (int i = 0; i < f.length; i++) {
accum.add(f[i]);
}
cls = cls.getSuperclass();
}
Field[] allFields = (Field[]) accum.toArray(new Field[accum.size()]);
//stop extract AllFieldsSnippet
}
}
Thank with us