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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
kezman9
Posts: 26
Joined: Fri Jul 06, 2012 1:08 am
Contact:

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

Post 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

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

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

kezman9
Posts: 26
Joined: Fri Jul 06, 2012 1:08 am
Contact:

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

Post 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

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

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

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest