Ranadhir Nag wrote:
Initializing static final fields in no-arg ctor?
I thought such fields need to be initialized before the first instance of a class comes into existence ,which essentially means a staci block or initialization at declaration.
Initializing at ctor is not an option - correct me if i am wrong on this.
Yes, of course, you're right ! (how can one write such a nonsense like I did

)
Ranadhir Nag wrote:
However,theoretically,for a session EJB,what is the difference in initializing a member final variable(non-static) in ctor and ejbCreate methods.
According to Java rules (vindication, yeah

) a final non-static variable must have been initialized after an instance of a class has been created (i.e. after a constructor has been executed). So, if you initialize a final non-static variable in ejbCreate method the (ejb) class won't compile.
In general the difference between the no-arg constructor and post-construct / ejbCreate methods is that in the latter you can use some methods from ejb context or do JNDI lookups that aren't allowed in the constructor.