I'm working with a Java API used for "macros" that automate a piece of software. The API has, among other things, the classes Simulation
(a global state of sorts) and FunctionManager
. There's nothing I can do to modify these classes.
I'd like to make a BetterFunctionManager
class that extends FunctionManager
because the latter lacks some useful features. But I don't know how to do this, because FunctionManager
can't be instantiated directly. It must be gotten from Simulation
, like this:
Simulation simulation = getCurrentSimulation();
FunctionManager functionManager = simulation.getFunctionManager();
Note that Simulation
can't be instantiated directly either; it must be gotten via getCurrentSimulation()
(the current simulation is determined at runtime by the macro interpreter).
I can't downcast; the following throws a ClassCastException:
BetterFunctionManager betterFunctionManager = simulation.getFunctionManager();
How can I construct BetterFieldFunctionManager
?
Simulation
attribute, and work your way into all the methods to redefine. You can then have it return yourBetterFunctionManager
. – PraenomenFunctionManager
expose all members as public which you need inBetterFieldFunctionManager
? Or do you need access to protected members also? – Fanchette