Using Reflection API to set the private member values
@ToString
class ReflectionA{
private int a;
}
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
ReflectionA reflectionA=new ReflectionA();
ReflectionA reflection=new ReflectionA();
Field field=reflectionA.getClass().getDeclaredField("a"); // pass the field/variable name
field.setAccessible(true); // mark as accessible of private member
field.set(reflection,58); // pass the object in 1st arg and in 2nd arg supply value of that field
System.out.println(reflectionA);
System.out.println(reflection);
}
Using Reflection API to set the private member values