import org.apache.commons.lang3.reflect.FieldUtils;
public class ReflectionExample {
private String name;
private int age;
public ReflectionExample(String name, int age) {
this.name = name;
this.age = age;
}
public static void main(String[] args) throws IllegalAccessException {
ReflectionExample example = new ReflectionExample("John", 30);
String name = (String) FieldUtils.readField(example, "name", true);
int age = (int) FieldUtils.readField(example, "age", true);
System.out.println("Name: " + name);
System.out.println("Age: " + age);
FieldUtils.writeField(example, "name", "Alice", true);
FieldUtils.writeField(example, "age", 35, true);
System.out.println("Updated Name: " + example.getName());
System.out.println("Updated Age: " + example.getAge());
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}