-1

I am rather sure that this is impossible, but I think I might as well try. I have some existing code which I do not own, and I want to keep my code completely seperate, say this was the original class

public class myClass
{
    public static void doStuffs()
        {
             x = x + 1;
        }
}

and the other class had:

public static void setData()
       {
             //Set the data
       }

Is it possible to call doStuffs() when setData() is called without modifying the the actual setData() method? If so how?

4

2 回答 2

0

可以通过字节码检测: ByteCodeInstrumentation

有几个库可以提供帮助,例如ASMJavassist

于 2012-12-17T09:37:16.243 回答
0

是的,可以使用Javaassist
您可以使用此库在运行时修改字节码

于 2012-12-17T09:24:04.597 回答