Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Question about the use of "final" in beans

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic