Skip to content

Commit 5c62b6f

Browse files
carimurasmthelusive
authored andcommitted
some grammar cleanup, hopefully all ok
1 parent 344575a commit 5c62b6f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

app/pages/learn/01_tutorial/04_mastering-the-api/02_invoke/00_methodhandle.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ category_order: 1
88
layout: learn/tutorial.html
99
subheader_select: tutorials
1010
main_css_id: learn
11-
description: "What is method handle mechanism, how is it different from Reflection API, and what tooling does it provide."
11+
description: "What are method handles, how are they different from the Reflection API, and what tooling do they provide?"
1212
author: ["NataliiaDziubenko"]
1313
toc:
1414
- What are method handles {intro}
@@ -28,14 +28,14 @@ last_update: 2024-05-04
2828

2929
<a id="intro">&nbsp;</a>
3030
## What are method handles
31-
Method handles are a low level mechanism used for method lookup and invocation. It is often compared to reflection,
32-
because both the Reflection API and method handles provide means to invoke methods, constructors and access fields.
31+
Method handles are a low-level mechanism used for method lookup and invocation. They are often compared to reflection,
32+
because both the Reflection API and method handles provide a means to invoke methods, constructors, and access fields.
3333

3434
What exactly is a method handle? It's a directly invocable reference to an underlying method, constructor, or field.
35-
The Method Handle API allows manipulations on top of simple pointer to the method, that allow us to insert or reorder the
36-
arguments, or transform the return values, for example.
35+
The Method Handle API allows manipulations on top of a simple pointer to the method that allows us to insert or reorder the
36+
arguments, transform the return values, etc.
3737

38-
Let's take a closer look at what method handle mechanism can provide and how we can effectively use it.
38+
Let's take a closer look at what method handles can provide and how we can effectively use them.
3939

4040
<a id="access">&nbsp;</a>
4141
## Access checking
@@ -55,8 +55,8 @@ To create a method handle we first need to create a [`Lookup`](javadoc:Lookup) o
5555
creating method handles. Depending on how the lookup object itself or the method handles are going to be used, we can
5656
decide whether we should limit its access level.
5757

58-
For example, if we create a method handle pointing to a private method and that method handle is accessible from outside,
59-
so is the private method. Normally we would like to avoid that. One way is to make the lookup object and method handle
58+
For example, if we create a method handle pointing to a private method and that method handle is accessible from the outside,
59+
then the private method is as well. Normally we would like to avoid that. One way is to make the lookup object and method handle
6060
`private` too. Another option is to create the lookup object using the [`MethodHandles.publicLookup`](javadoc:MethodHandles.publicLookup())
6161
method, so it will only be able to search for public members in public classes within packages that are exported unconditionally:
6262

@@ -138,7 +138,7 @@ String result = (String) replaceMethodHandle.invoke((Object)"dummy", (Object)'d'
138138
```
139139

140140
One other alternative to invoke a method handle is to use [`MethodHandle.invokeWithArguments`](javadoc:MethodHandle.invokeWithArguments(Object...)).
141-
The result of this method invocation is equivalent to `invoke`, with the only difference that all the arguments can be
141+
The result of this method invocation is equivalent to `invoke`, with the only difference being that all the arguments can be
142142
provided as an array or list of objects.
143143

144144
One interesting feature of this method is that if the number of provided arguments exceeds the expected number, all the
@@ -147,8 +147,8 @@ leftover arguments will be squashed into the last argument, which will be treate
147147
<a id="fields">&nbsp;</a>
148148
## Accessing fields
149149
It is possible to create method handles that have read or write access to fields. For instance fields, this is
150-
facilitated by [`findGetter`](javadoc:MethodHandles.Lookup.findGetter(Class,String,Class)) and
151-
[`findSetter`](javadoc:MethodHandles.Lookup.findSetter(Class,String,Class)) methods, and for static fields, by
150+
facilitated by the [`findGetter`](javadoc:MethodHandles.Lookup.findGetter(Class,String,Class)) and
151+
[`findSetter`](javadoc:MethodHandles.Lookup.findSetter(Class,String,Class)) methods, and for static fields, by the
152152
[`findStaticGetter`](javadoc:MethodHandles.Lookup.findStaticGetter(Class,String,Class)) and
153153
[`findStaticSetter`](javadoc:MethodHandles.Lookup.findStaticSetter(Class,String,Class)) methods. We don't need to provide
154154
a `MethodType` instance; instead, we should provide a single type, which is the type of the field.
@@ -534,7 +534,7 @@ private static String resultTransform(String value) {
534534
}
535535
```
536536

537-
Here is the method handle for our transformator method:
537+
Here is the method handle for our transformer method:
538538

539539
```java
540540
MethodHandle resultTransform = lookup.findStatic(Example.class, "resultTransform", MethodType.methodType(String.class, String.class));
@@ -614,7 +614,7 @@ Field field = MethodHandles.reflectAs(Field.class, getterMethodHandle); // same
614614
<a id="conclusion">&nbsp;</a>
615615
## Conclusion
616616
In this tutorial, we have looked into the method handle mechanism and learned how to efficiently use it. We now know,
617-
that method handles provide means for efficient method invocation, but this mechanism is not meant to replace the
617+
that method handles provide a means for efficient method invocation, but this mechanism is not meant to replace the
618618
Reflection API.
619619

620620
Method handles offer a performance advantage for method invocation due to a different access checking approach. However,

0 commit comments

Comments
 (0)