Junior in Java; using reflection is possible to access private fields (not asking how, Question 1 and Question 2) Ok.
My questions are related with the nature of this behaviour.
- Is there any limitation? Can I access any field of any
.class
I come across? - During my code, once you set the visibility of a field to lets say "public", is it changed forever or just up to the end of the context (method, if, for...)? Code below
- Is it ok for everybody? I mean, Seniors programmers of StackOverflow, is it a security breach?
Code [EDITED]:
Field f = obj.getClass().getDeclaredField("field");
if (...) {
f.setAccessible(true);
// f IS accesible
}
// is f accesible?