@@ -31,7 +31,7 @@ last_update: 2024-05-04
31
31
Method handles are a low level mechanism used for method lookup and invocation. It is often compared to reflection,
32
32
because both the Reflection API and method handles provide means to invoke methods, constructors and access fields.
33
33
34
- What exactly is a method handle? It's a direct reference to a method, constructor, or field, which can be invoked .
34
+ What exactly is a method handle? It's a directly invocable reference to an underlying method, constructor, or field.
35
35
The Method Handle API allows manipulations on top of simple pointer to the method, that allow us to insert or reorder the
36
36
arguments, or transform the return values, for example.
37
37
@@ -618,11 +618,9 @@ In this tutorial, we have looked into the method handle mechanism and learned ho
618
618
that method handles provide means for efficient method invocation, but this mechanism is not meant to replace the
619
619
Reflection API.
620
620
621
- The biggest differences are:
621
+ Method handles offer a performance advantage for method invocation due to a different access checking approach. However,
622
+ since access is checked only on method handle creation, method handles should be passed around with caution.
622
623
623
- - Access checking happens only on method handle creation, which means that method handles should be passed around with
624
- caution.
625
- - Method invocation is more performant with method handles due to a different access checking approach.
626
- - Method handles don't provide any tooling for listing the class members and inspecting their properties.
627
- - Method handles make it easy to wrap the direct pointers to methods and fields into more complicated logic which
628
- includes argument and return value manipulations.
624
+ Unlike the Reflection API, method handles don't provide any tooling for listing class members and inspecting their properties.
625
+ On the other hand, the Method Handle API allows us to wrap direct pointers to methods and fields into more complex
626
+ logic, such as argument and return value manipulations.
0 commit comments