Known Bugs of the Replace Inheritance with Delegation Refactoring

class Super {
      Super() {
            m();
      }
      void m() {}
      void n() {}
}
 
class Sub extends Super {
      Sub() {
            super();
      }
      void m() {
            n();
      }
}

Note that calling overridable methods from a construcor (which can also occur without delegation) is a known pitfall of Java and can be prevented by separating instantiation from initialization.

public interface I {}

public
class Super implements I {}

public class Sub extends Super {  
      I make() {
            return new Sub();
      }
      void cast() {
            Super o = (Super) make();
      }
      public static void main(String[] args) {
            new Sub().cast();
      }
}

the cast to Super is ignored, causing a Type Cast Error after the refactoring.

public interface Inter {}

public
class Super implements Inter {
      public void exportThisTo(Client c) {
            c.receive(this);
      }
}

public class Sub extends Super {}


public
class Client {
      Sub server = new Sub();

     
void receive(Inter object) {
            assert object == server;
      }

      void send() {
            server.exportThisTo(this);
      }
     
      public static void main(String[] args) {
            (new Client()).send();
      }
}