I am curious regarding java object copies and inheritance. Lets say I have the following two classes:
abstract class Algorithm {
  public abstract void run();
}
class Specialized extends Algorithm {
  @Override
  public void run();
}
Now I want to test the specialized algorithm. And I really want to do this in parallel with multiple instances / parameters. The problem is that the run method is not reentrant, so I have to have per-thread instances of Specialized. Of course any kind AlgorithmRunner should work with the abstract class Algorithm to be able to test multiple different specializations. The problem is that I would need to construct a new ? extends Algorithm from an existing one in a generic fashion. How can I achieve this? I could easily write copy constructors for each kind of specialization but that would require switches using instanceof checks which I would rather avoid.
 
     
    