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
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 ]
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.