1

On this example is presented a way how to call a private method of class A, from another class?

Since on "regular way" we can not use this, is this violating of encapsulation?

user16401
  • 193
  • 1
  • 9
  • 1
    Go through this link: http://stackoverflow.com/questions/2481862/how-to-limit-setaccessible-to-only-legitimate-uses – JNL Sep 03 '13 at 13:49

2 Answers2

2

Yes its a violation. And that is one of the reasons why you should carefully use Reflection. For more look here. It can be somewhat controlled by using SecurityManager

Community
  • 1
  • 1
rocketboy
  • 9,573
  • 2
  • 34
  • 36
1

Yes, it is, and using reflection is explicitly a means of evading the usual access controls. If it's really important to prevent this, you can install a SecurityManager that limits reflection.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152