Monday, February 9, 2009

Java Reflection API

Java Reflection is a powerful tools to dynamically instantiate objects. It is especially helpful and reduce the amount of code to be written. Fields, Methods and Constructors are the members of the reflectors.

Sample codes from Java

http://java.sun.com/docs/books/tutorial/reflect/member/fieldModifiers.html

http://java.sun.com/docs/books/tutorial/reflect/member/methodModifiers.html

http://java.sun.com/docs/books/tutorial/reflect/member/ctorModifiers.html

Java Tips:

The Class.getField() and Class.getFields() methods return the public member field(s) of the class, enum, or interface represented by the Class object. To retrieve all
fields declared (but not inherited) in the Class, use the Class.getDeclaredFields() method.

But, one note is that

An IllegalAccessException may be thrown if an attempt is made to
get or set the value of a private or otherwise inaccessible field or to set the
value of a final field (regardless of its access modifiers).

The same goes to Method. This is kind of a setback.

http://java.sun.com/docs/books/tutorial/reflect/TOC.html

No comments:

Post a Comment

Windows 7 - STOP 0x0000007B (0xFFFFF880009A97E8 0xFFFFFFFFC0000034 0x0000000000 0x0000000000)

If you encounter STOP 0x0000007B (0xFFFFF880009A97E8 0xFFFFFFFFC0000034 0x0000000000 0x0000000000) blue screen of death. This is very like...