Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
可以使用java工具在运行时更改静态方法吗?_Java_Instrumentation - Fatal编程技术网

可以使用java工具在运行时更改静态方法吗?

可以使用java工具在运行时更改静态方法吗?,java,instrumentation,Java,Instrumentation,我需要更改第三方库中的静态方法。我已经转换了实例方法,但不确定同样的事情是否适用于静态方法 @Override public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws Il

我需要更改第三方库中的静态方法。我已经转换了实例方法,但不确定同样的事情是否适用于静态方法

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

}
我在MyClass.java中有几个静态方法,称为myMethod。我需要在运行时更改myMethod的实现。 基本上,我扩展了ClassFileTransformer并重写了byte[]转换方法,类似于bellow。这对实例方法有效,但我不确定是否可以对静态方法也有效

@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
                        ProtectionDomain protectionDomain, byte[] classfileBuffer)
    throws IllegalClassFormatException {

}
@覆盖
公共字节[]转换(类加载器、字符串类名、类被重新定义、,
ProtectionDomain ProtectionDomain,字节[]classfileBuffer)
抛出IllegalClassFormatException{
}

是的,当然这是可能的。您可以更改整个类文件。对于大多数VM,您只能更改方法的实现,而不能更改其签名。方法是否是静态的并不重要