Why is it possible to use Reflections in Java 8 to modify only the second example and not the first example? Can anyone help :) .-.
public class Test {
private String name = "Hans";
}
---------------------------------------------------------
public class Test {
private String name;
public Test() {
name = "Hans";
}
}
----------------------------------------------
Test test = new Test();
Field field = Test.class.getDeclaredField("name");
field.setAccessible(true);
field.set(test, "Paul");
Aucun commentaire:
Enregistrer un commentaire