khan gul wrote:Thanks Ivan,
Just for the argument of understanding, how static method will cause problem especially if its thread safe? As in the above example, the method is thread safe so in my opinion it even better to have a static method rather than non static method.
I would appreciate if you can elaborate what type of problem this may cause if we have static method with @WebMethod annotation.
regards,
khan
Hi Khan,
What are the reason you feel that it is better to have static methods rather than non static methods. Could you please elaborate on this?
Now here is my understanding, specs advise to use non static methods specially for the container managed objects like ejbs,
servlets, webservice components etc, because a run time object is provided by the container which would extend the components we as a developer develops. Now these run time objects include some additional features and functionalities specific to that container and were not handled by the components we design. In order to not to interfere with container, specs do not recommend to use static methods.
As you might be aware of overriding vs hiding, which was also clearly explained
here, we will not be able to utilize the
polymorphism, which is inherently used at run time. We invoke the methods on the interface, but at run time container delegates the invocation to the run time object it created and also which extends the components we designed.
So, that is one of the primary reasons, why static methods are not recommended. What do you think about this ?