问题
I am using MethodCall.setsField() to try to set an instance field on another instance.
My generated class that is doing the field-setting, GC
, is trying to set the value of an instance field in an instance of something it has created (CI
). So the field's declaring type is CI
; my field-setting code resides in GC
(which is in the same package as CI
but otherwise unrelated to it).
The ByteBuddy checks seem to indicate that although GC and CI are in the same package, GC must be assignable to CI in order to set this field! That greatly surprised me, but I am not a bytecode expert, and I might very well be overlooking something obvious. Could someone kindly explain why this check is necessary?
回答1:
The method call sets the field implicitly on the this instance on which the method is invoked. For this to be possible, a non-static field must be declared by a super type of the type on which the method is invoked.
If you think this is too strict, please file an issue with an example of the code you are trying to generate, including the code to generate it which is currently failing. Maybe I am not thinking straight about this and if there's a restriction to be lifted, I would surely do it.
来源:https://stackoverflow.com/questions/64582521/are-bytebuddys-field-setting-checks-too-strict