From wikipedia :
reflection is the ability of a computer program to examine and modify the structure and behavior (in particular, the values, metadata, properties and functions) of an object at runtime.
Can someone give me a concrete example of changing the structure of an object? I know the following example.
Object foo = Class.forName("complete.classpath.and.Foo").newInstance(); Method m = foo.getClass().getDeclaredMethod("hello", new Class<?>[0]); m.invoke(foo);
Other ways to get a class and learn structures. But the questions are, how is the modification done?
In java, reflection is not fully supported, as defined in wikipedia.
Field.setAccessible(true) Method.setAccessible(true) , , .
Field.setAccessible(true)
Method.setAccessible(true)
, , . hibernate , , . -, .
Java - , javascript, .
, . , , javassist asm libs. .
, , . , , , .
" ".
. - , .
java - . - CGLIB.
(java.lang.reflect) - , - setAccessible, , . http://ru.wikipedia.org/wiki/Byte_Code_Engineering_Library , Java
java.lang.reflect
setAccessible