Using reflection to modify the structure of an object

Viewed 1954

From wikipedia:

reflection is the ability of a computer program to examine and modify the structure and behavior (specifically the values, meta-data, properties and functions) of an object at runtime.

Can anyone give me a concrete example of modifying the structure of an object? I'm aware of 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 the class and examine structures. But the questions is how modify is done?

4 Answers
Related