I'm working with pre-existing classes, and I am not permitted to alter any of them. I am working within the same package as the classes, and am trying to implement new functionality.
In one of the classes, there is a static void step()
, which is called every time a significant action is completed. This method renders the view, and then calls Thread.sleep()
for varying amounts of time.
Part of the functionality I need to implement needs to be called every time a significant action is completed, before the view renders. This means that I need a way to execute code every time step
is called, before anything else in step
is allowed to execute.
I can't modify step
, since it's in a class I can't touch, and I can't extend its enclosing class, since it's a static method, and so every call to it in those untouchable classes is a class-method call, rather than an object reference. That means that even if and when I override the method, it won't be called by any of the other classes. The way I see it, I have two options: Find a way to automatically insert a modified method into the class whenever it is loaded, or find a way to insert a separate method into the process whenever step
is called. My research has been fruitless in both veins.
EDIT 1: As I've come to learn, there are extensions to complete these tasks. However, any solutions I use have to stay within the standard JDK.