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.
Well, not really... Not in the meaning as if you have this empty class
and then do
you could then do:
The true answer is "You don't want to do that!".
It IS possible to do it by manipulating on the byte code with some really fancy tricks. However... you don't want to do that. In most cases it is better to use Aspect Oriented Programing and put in cutpoints where you need to manipulate the code. Or use a Visitor pattern or Strategy pattern. Or even use the horrible ProxyClass (see See http://www.exampledepot.com/egs/java.lang.reflect/ProxyClass.html) if you are needing a custom implementation of an interface, and you only know the details at runtime.
Most of the time, it is better to change the model and use some sort of dependency injection of a custom class into another than trying to manipulate on the actual object. As stated in THGTTG, it is better to remove the mountain than trying to make it invisible...
Joined: Nov 04, 2005
I didn't think so and your explanation is very helpful...THANK YOU!