1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
When do I need to use reflection?
JavaFAQ Home » General Java
Question: When do I need to use
Answer: Reflection is a feature in the
Java programming language.
It allows an executing Java program to examine or "introspect"
upon itself, and manipulate internal properties of the program.
For example, it's possible for a Java class to obtain the names
of all its members and display them.
The ability to examine and manipulate a Java class from within
itself may not sound like very much, but in other programming
languages this feature simply doesn't exist. For example, there
is no way in a Pascal, C, or C++ program to obtain information
about the functions defined within that program.
The reflection API represents, or reflects, the classes,
interfaces, and objects in the current Java Virtual Machine.
You'll want to use the reflection API if you are writing
development tools such as debuggers, class browsers, and GUI
builders. With the reflection API you can:
Determine the class of an object.
Get information about a class's modifiers, fields, methods,
constructors, and superclasses.
Find out what constants and method declarations belong to an
Create an instance of a class whose name is not known until
Get and set the value of an object's field, even if the field
name is unknown to your program until runtime.
Invoke a method on an object, even if the method is not known
Create a new array, whose size and component types is not known
until runtime, and then modify the array's
Read more about reflection here:
Printer Friendly Page
Send to a Friend
Search here again if you need more info!