Results 1 to 1 of 1
-
Getting class field information using Reflection
The code snippet below gets all the fields of MyClass and displays the attribute name, type, modifiers, class and super class.
Java Code:try { Class c = Class.forName("MyClass"); Field list[] = c.getDeclaredFields(); for (int i = 0; i < list.length; i++) { Field fld = list[i]; System.out.println("Class: " +fld.getDeclaringClass()); System.out.println("Super Class: " +fld.getDeclaringClass().getSuperclass()); System.out.println("Attribute name: " + fld.getName()); System.out.println("Data type: " + fld.getType()); int mod = fld.getModifiers(); System.out.println("Modifiers: " +Modifier.toString(mod)); System.out.println("======================================"); } } catch (Throwable e) { System.err.println(e); }
Similar Threads
-
Using reflection to create, fill, and display an array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM -
Getting method names using Reflection
By Java Tip in forum Java TipReplies: 0Last Post: 01-24-2008, 03:18 PM -
Execution methods – Reflection
By Java Tip in forum Java TipReplies: 0Last Post: 11-15-2007, 03:19 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