Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about the use of "final" in beans

 
Robert Miller
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm new to EJB and am working my way through Head First EJB. I've noticed several times the authors point out that bean classes cannot be declared final, and that business methods in bean classes cannot be declared final. Can someone please explain the reason for this restriction? Is the container going to subclass the bean?

Thanks!

Robert
 
Severin Stoeckli
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm... good question.

I was searching in the spec, in chapter 8.2 you can see an example of all classes and interfaces that a container provider may create. In this example the AcmeCartBean extends the CartBean, therefore the CartBean can't be final.

7.10.2 of the spec:

7.10.2 Session bean class
...
� The class must be defined as public, must not be final, and must not be abstract.

==> it is guaranteed to the container provider that he CAN extend your beenclass (but it's not an obligation).

Severin
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bean classes must not be final in order to grant maximum freedom to the container providers when they have to integrate your beans into their container. The integration can be done in several ways. The three most common ways are delegation, extension and code generation. In case of extension, the container-specific classes must be able to extend from your bean class in order to integrate it in the container. Don't worry too much about this for the exam, you won't be tested on any container-specific stuff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic