aspose file tools*
The moose likes Beginning Java and the fly likes How could I do for acess a private method like that from another class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How could I do for acess a private method like that from another class?" Watch "How could I do for acess a private method like that from another class?" New topic
Author

How could I do for acess a private method like that from another class?

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234


How could I do for acess a private method like that from another class?
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Using reflection. See http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
Thank you very much.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3681
    
  16
Of course, private methods are designed not to be accessed from outside the class. If you find you need to do this, you may need to review your design.


Joanne
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
Also, doing this may break the class if you're not careful (and may not be possible in the presence of a security manager, like if the code runs as part of a server).


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How could I do for acess a private method like that from another class?