![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
R :
RE :
REF :
Reflection (computer science) |
|
|
Reflection (computer science)In computer science, reflection is the ability of a program to examine and possibly modify its high level structure at runtime. It is most common in high-level virtual machine programming languages like Smalltalk, and less common in low-level programming languages like C.When program source code is compiled, information about the structure of the program is normally lost as lower level code (typically assembly language code) is produced. If a system supports reflection, the structure is preserved as metadata with the emitted code. Known platforms supporting reflection are:
ImplementationA language supporting reflection provides a number of features available at runtime that would otherwise be very obscure or impossible to accomplish in a lower-level language. Some of these features include:
ExampleThe following is an example in Java. Consider two pieces of code // Without reflection Foo foo = new Foo (); foo.hello (); // With reflection Class clazz = Class.forName ("Foo"); Method method = clazz.getMethod ("hello", null); method.invoke (clazz.newInstance (), null); The both code creates the instance of a class 'Foo' and calls its method 'hello'. The difference is that in the first piece, the name of the class and the method is hard-coded; it is not possible to use a class of another name. In the second piece, the names of the class and the method can vary at runtime. (See java.lang.reflect for more of this feature.) References
|
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |