Groovy如何能够访问Java类的私有方法? [英] How is Groovy able to access private methods of a Java class?
问题描述
MethodHandle
类使用 invokedynamic
字节码指令吗?我认为Java使用 invokespecial
指令来调用 private
方法和 invokevirtual
for public
权限访问修饰符?在Java中,所以它希望不直接依赖字节码,它不是使用反射API 。
有关更多详细信息,请查看 java.lang.reflect
,那么您将看到它在场景后面如何使用Reflection API。
Groovy can access private methods and variables of a Java class. How does Groovy do this behind the scene? Is it because of the use of invokedynamic
bytecode instruction which is used by MethodHandle
class? I think Java uses invokespecial
instruction for calling private
methods and invokevirtual
for public
right which respects access modifiers?
Groovy is written in Java, so it hopefully doesn't rely on the byte code directly, it doesn't it using the Reflection API.
For more details check for java.lang.reflect
in the source code, you will then see how it uses the Reflection API behind the scene.
这篇关于Groovy如何能够访问Java类的私有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!