Results 1 to 1 of 1
-
Class Reflection: Finding field infomation
Java Code:import java.awt.GridBagConstraints; import java.lang.reflect.Field; public class SampleField { public static void main(String[] args) { GridBagConstraints g = new GridBagConstraints(); printFieldNames(g); } static void printFieldNames(Object o) { Class c = o.getClass(); Field[] publicFields = c.getFields(); for (int i = 0; i < publicFields.length; i++) { String fieldName = publicFields[i].getName(); Class typeClass = publicFields[i].getType(); String fieldType = typeClass.getName(); System.out.println("Name: " + fieldName + ", Type: " + fieldType); } } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Class Reflection: Finding implemented interfaces
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:09 PM -
Array Reflection: Multi Array Reflection
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
Getting class field information using Reflection
By Java Tip in forum Java TipReplies: 0Last Post: 01-24-2008, 03:20 PM -
Getting methods of a Class - Reflection
By Java Tip in forum Java TipReplies: 0Last Post: 11-15-2007, 03:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks