SuperClone

Since Checkstyle 3.2

Description

Checks that an overriding clone() method invokes super.clone(). Does not check native methods, as they have no possible java defined implementation.

Reference: Object.clone().

Examples

To configure the check:

<module name="Checker">
  <module name="TreeWalker">
    <module name="SuperClone"/>
  </module>
</module>
        

Example:

class A {

 public Object clone() { // OK
  return super.clone();
 }
}

class B {
private int b;

 public B clone() { // violation, does not call super.clone()
  B other = new B();
  other.b = this.b;
  return other;
 }
}

class C {

 public C clone() { // OK
  return (C) super.clone();
 }
}
        

Example of Usage

Violation Messages

All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.

Package

com.puppycrawl.tools.checkstyle.checks.coding

Parent Module

TreeWalker