Using reflection to change the structure of an object

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?

+4
source share
4 answers

In java, reflection is not fully supported, as defined in wikipedia.

Field.setAccessible(true) Method.setAccessible(true) , , .

, , . hibernate , , . -, .

Java - , javascript, .

+1

, . , , javassist asm libs. .

, , . , , , .

+2

" ".

. - , .

java - . - CGLIB.

+2

(java.lang.reflect) - , - setAccessible, , . http://ru.wikipedia.org/wiki/Byte_Code_Engineering_Library , Java

+1

All Articles