Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
class Base implements Cloneable {
  public Object clone() throws CloneNotSupportedException {
    return new Base();	 
  }
  protected static void doLogic() {
    System.out.println(""Superclass doLogic"");
  }
}

class Subclass1 extends Base {
  public Object clone() throws CloneNotSupportedException {
    return super.clone();
  }
  protected static void doLogic() {
    System.out.println(""Subclass doLogic"");
  }
  public static void main(String[] args) {
    Subclass1 s = new Subclass1();
    try {
      Object sc = s.clone(); // get's Base obj instead of subclass'
      System.out.println(sc.getClass().hashCode()); // a possible mistake
      // ((Subclass1)sc).doLogic(); // Produces ClassCastException, disqualified
    } catch (CloneNotSupportedException e) { /* ... */ }
  }
}

...

MET34-J. Follow the general contract when implementing the compareTo method            12. Methods (MET)      13. Exceptional Behavior (EXC)      MET36-J. Do not use deprecated or obsolete methods