I found the below code snippet :
import java.lang.reflect.Field;
public class Test {
public static void main(String[] args) {
System.out.println("Inside main");
}
static {
try {
Field value = String.class.getDeclaredField("value");
value.setAccessible(true);
value.set("Inside main", value.get("Inside static bolck"));
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
As per my understanding the output should be Inside static bolck
but the output comes as Inside stat
, the same character length of Inside main
.
*If i increase the length of Inside main the output length is also getting increased.
Can anybody please explain?
I do not have much knowledge in Reflection.