Is it possible to achieve such an assignment. The article here deals with private static
field members but it does not help in this case as final members cannot be assigned.
Justification for using private static final
as a qualifier for the member:
- The data member is a ServiceClient so it makes sense to have it attached to type as it does not depend on the instance. Its thread safe too, so it will improve performance as I will not initialize the client for each instance.
- The service client itself is a bean, having singleton scope. Hence actually there is only one instance. Since there will always be one instance, there is no point in allowing reassignment.
- Since this client is only be used by methods of this class, it is private.
I am not exactly sure if this is an anti-pattern, but if it is then do my justification qualify to use it? If yes, then how can it be done. If no, then please suggest an alternative (and I would still be interested to know how can this be achieved, just for knowledge purposes).