Reputation: 7372
I'm missing something obvious here, but I don't see the declared methods when I subclass a Class using ByteBuddy.
Object.class.getDeclaredMethods()
result:
[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()]
Now using ByteBuddy:
new ByteBuddy().subclass(Object.class)
.make()
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION)
.getLoaded().getDeclaredMethods()
result:
[]
Upvotes: 0
Views: 742
Reputation: 44032
As mentioned in the comments, getDeclaredMethods
only returns the methods that are explicitly declared by a class. As you do not override any methods, there are zero such methods.
If you added an override for all methods, you would see them again (the non-final ones):
new ByteBuddy().subclass(Object.class)
.method(any()).intercept(SuperMethodCall.INSTANCE)
.make()
.load(getClass().getClassLoader())
.getLoaded()
.getDeclaredMethods()
Alternatively, the reflection API offers getMethods()
for finding all public virtual methods.
Upvotes: 1