Page 1 of 1

About Question enthuware.oce-ejbd.v6.2.345 :

Posted: Mon Jul 29, 2013 11:01 am
by kezman9
The explanation for third answer says:
EJBs must not have Non-final static fields.
Specifaction doesn't prohibit EJB from having non-final static field. It says EJB must not use it (for writing). Read-only static fields are allowed.

21.2.2
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.
J

Re: About Question enthuware.oce-ejbd.v6.2.345 :

Posted: Mon Jul 29, 2013 4:46 pm
by admin
That's seems a little weird. In the first sentence it says "must not". In the third, it says "recommended". How can you ensure a read only field without making it final?

But you are right. This should be added to the explanation.
thank you for your feedback!
Paul.

Re: About Question enthuware.oce-ejbd.v6.2.345 :

Posted: Tue Jul 30, 2013 3:47 am
by kezman9
Hi Paul,
I made a test on Glassfish and tried to write a value to non-final static field in stateles bean. Much to my surprise i didn't get any exception nor warning. My understaing is that me as a programmer have to remember that writing to non-final static field could cause errors. That's why it is recommended to mark these kind of fields as final.

Thanks,
Jarek

Re: About Question enthuware.oce-ejbd.v6.2.345 :

Posted: Fri Apr 24, 2015 5:37 pm
by himaiMinh
Much to my surprise i didn't get any exception nor warning.
This is true. The compiler compiles your EJB code if you define a static variable in the EJB class.
But it is not a recommended practice.