Is it possible to reflectively override a method for a given instance of a class?
Precondition: Game has an override-able method act().
public class Foo {
public Method[] getMethods() {
Class s = Game.class;
return s.getMethods();
}
public void override()
{
Method[] arr = getMethods()
for (int i = 0; i<arr.length; i++)
{
if (arr[i].toGenericString().contains("act()")
{
// code to override method (it can just disable to method for all i care)
}
}
}
}
If Game is an interface or implements an interface with the method
act()you can use Proxy for that. If the interface is small, the most elegant way would probably be to create a class implementing it employing the Decorator design pattern.