It's not a secret anymore!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes PostConstruct and PreDestroy methods can be have any access modifier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "PostConstruct and PreDestroy methods can be have any access modifier" Watch "PostConstruct and PreDestroy methods can be have any access modifier" New topic
Author

PostConstruct and PreDestroy methods can be have any access modifier

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Page 81 of EJB in action: PostConstruct and PreDestroy methods can be have any access modifier. I can't understand, how is this permitted and how can this work fine. I had a private @PostConstruct method in a stateless session bean and it worked fine. Since PostConstruct is just a method call, how can container which is outside the class invoke a private method.
Please explain.


SCJP, SCWCD, SCBCD
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
Please take time to respond to this question.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

For the container it is the metadata that is required (i.e., the annotations).


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
I understand the metadata part of it, But in the end lifecycle callbacks are just methods, and if a method is marked private, How can it be invoked from a code like the container outside the class.

Experts/Ranchers, Please take time and reply.
 
Consider Paul's rocket mass heater.
 
subject: PostConstruct and PreDestroy methods can be have any access modifier