Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to prevent reflection to access private methods and members in java classes?

 
agilemanoj kumar
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Private members and methods can be accessed by outer world using reflection concept in java.

Please have a look on http://www.onjava.com/pub/a/onjava/2003/11/12/reflection.html this link. This link gives the information about REFLECTION which can be used to access private methods and it is well explained.

Now my question is How to prevent reflection to access private methods and members in java classes?
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to use the security manager; see the Security Features in Java SE tutorial to start with. This is how applets are prevented from accessing local files, and from using reflection to get around these limits.

In particular, setAccessible(true) checks for ReflectPermission("suppressAccessChecks") before allowing access to private members.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic