我在这里遗漏了一些明显的东西,但是当我使用 ByteBuddy 子类化一个类时,我看不到声明的方法。
Object.class.getDeclaredMethods()
结果:
[protected void java.lang.Object.finalize() throws java.lang.Throwable, public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException, public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException, public final void java.lang.Object.wait() throws java.lang.InterruptedException, public boolean java.lang.Object.equals(java.lang.Object), public java.lang.String java.lang.Object.toString(), public native int java.lang.Object.hashCode(), public final native java.lang.Class java.lang.Object.getClass(), protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException, private static native void java.lang.Object.registerNatives(), public final native void java.lang.Object.notify(), public final native void java.lang.Object.notifyAll()]
现在使用 ByteBuddy:
new ByteBuddy().subclass(Object.class)
.make()
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
.getLoaded().getDeclaredMethods()
结果:
[]