Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static fields in Entity Bean

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • 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
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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 ]
 
Marin van Zandvoort
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic