...
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) { /* ... */ } } } |
...
MET14MET15-J. Follow the general contract when implementing the compareTo methodDo not use deprecated or obsolete methods 12. Methods (MET) MET15-J. Do not use deprecated or obsolete methods13. Exceptional Behavior (EXC)