This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
My method is passed an object whose type is not known until runtime. I know it must be a subclass of a system class e.g. java.awt.Component. I want to execute the standard API version of its method e.g. Component.getLocation() rather than some overridden version implemented by the object itself. Should I do this with reflection API? Are there any other alternatives?
From within the subclass itself, you can do this with super:
But from the "outside", there's no easy way to do that, other than reflection.
But why do you need to do this? It sounds like there might be something wrong with the design or architecture of your application if you feel you need to do this - do you not trust what the getLocation() method of the subclass does, or does the getLocation() method of the subclass do something else than it's supposed to do?
Some legacy code have changed the sematic of Component.getLocation() into relative to the Applet rather than the parent. Now I am writing a system monitoring/debugging tool for my appli. and I want to know the location using the original getLocation() semantic. I don't want to touch any existing code/recompile anything. It would be a big deal I don't want to get involved.