It's a common idiom, but like it is said in the wiki page, it should be used in applications, not in libraries that can be deployed as shared. In the most other libraries I've checked this is done. However, in Hibernate Validator this is not so.
Quoting the article:
The technical result of using static is obvious: there is only one Log reference shared across all instances of the class. This is clearly memory efficient; only one reference(4 or 8 bytes) is needed no matter how many instances are created. It is also CPU-efficient; the lookup required to find the Log instance is only done once, when the class is first referenced.
When writing stand-alone application code the use of static is a good idea.
However when the java code concerned is a library that may be deployed within a container of some sort (such as a J2EE server) then problems can occur. [..]
In most cases, simply leaving out the "static" qualifier from the Log reference is the correct solution.
|