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.