• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Static fields in Entity Bean

 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all
In EJB 2.0 Specification Chapter 24 p. 494, there is statement
"An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed.
Therefore, it is recommended that all static fields in the enterprise bean class be declared as final."
What's the meaning of that statement especially about read/write static fields?
Example I have a static ArrayList variable, when I add some objects into that variable, is it true that I write static field?
thanks
daniel
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since EJB are distribued objects, only static final read only varialbles are allowed.
If you declare a Arraylist as a final static and modify the contents of the list you are viloating the spec because the arraylist in the same EJB in another JVM will *not* see the changes. So whenever using static avraibles use static final and for *read-only* purpose.
[ September 07, 2003: Message edited by: Pradeep Bhat ]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I don't quite understand the spec's recommendation.
If declaring an object 'static final' doesn't prevent de object from being modified, I wouldn't be putting that phrase in the spec.

Am I perhaps missing something here?

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marin,
final prevents the reference from being modified. For some objects like Strings, this is enough. For other objects, you can call a set method and modify the object's state. Which doesn't meet the spirit of the final rule.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic