• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking private method using Reflection API  RSS feed

 
sujith Acharya
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched this in the forum, but couldn't find answer to this, so I am posting it here.

I tried to call private methods outside the class using the Reflection API. Is it not the violation of encapsulation in OOP?

Thanks
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is. Reflection is a powerful tool, and it shouldn't be used lightly. With it you can invalidate many invariants in Java. You can even modify Strings with it! That's why you should always consider setting up the right security permissions. With these you can disallow accessing private members.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!