title: Java: Extending Class At Runtime
body: <p>I have the capability to extend a class at compile time, but I need to be able to create an instance of this subclass at runtime using an instance of the superclass that was already instantiated.</p>
  
  <p>This should be possible in theory because superclass constructors are already called before the subclass constructor.</p>
  
  <p>I do not have access to the program sufficiently to change the instantiation to my subclass nor to interrupt the original instantiation.</p>
  
  <p>Use Case: There is an existing array of instances of class X. My code is loaded in after. I need to override one of the methods of one of the instances X with my loaded subclass Y extends X. The parent program accesses the objects only through that array, so I want to replace that array element with my Y instance, but it needs to behave as if it were instantiated originally into that array. I cannot just enclose the superclass instance and forward calls, and there are difficult complications with reinstantiating the superclass.</p>
  
  <p>I hope that is more clear.</p>