Checks for illegal instantiations where a factory method is preferred.
Rationale: Depending on the project, for some classes it might be
preferable to create instances through factory methods rather than
calling the constructor.
A simple example is the java.lang.Boolean class, to save memory and CPU
cycles it is preferable to use the predeifined constants TRUE and FALSE.
Constructor invocations should be replaced by calls to Boolean.valueOf().
Some extremely performance sensitive projects may require the use of factory
methods for other classes as well, to enforce the usage of number caches or
object pools.
Limitations: It is currently not possible to specify array classes.
An example of how to configure the check is:
<module name="IllegalInstantiation"/>
getAcceptableTokens
public int[] getAcceptableTokens()
Prevent user from changing tokens in the configuration.
- getAcceptableTokens in interface Check
Check
getDefaultTokens
public int[] getDefaultTokens()
- getDefaultTokens in interface Check
Check
getRequiredTokens
public int[] getRequiredTokens()
- getRequiredTokens in interface Check
Check
setClasses
public void setClasses(String aClassNames)
Sets the classes that are illegal to instantiate.
aClassNames
- a comma seperate list of class names