Cloneable class without 'clone()' method
Reports classes implementing the Cloneable interface that don't override the clone() method.
Such classes use the default implementation of clone(), which isn't public but protected, and which does not copy the mutable state of the class.
A quick-fix is available to generate a basic clone() method, which can be used as a basis for a properly functioning clone() method expected from a Cloneable class.
Example:
After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
CloneableClassWithoutClone- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Use the Ignore classes cloneable due to inheritance option to ignore classes that are Cloneable because they inherit from the Cloneable class.
Use the Ignore when Cloneable is necessary to call clone() method of super class option to ignore classes that require implementing Cloneable because they call the clone() method from a superclass.
Inspection options
Here you can find the description of settings available for the Cloneable class without 'clone()' method inspection, and the reference of their default values.
- Ignore classes cloneable due to inheritance
Default value:
Selected- Ignore if Cloneable is necessary to call the clone() method of a superclass
Default value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |