Skip to content

Commit 028a203

Browse files
committed
Update MethodHandleUtils.java
1 parent aa5e1b9 commit 028a203

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandleUtils.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,36 @@
5050
import static java.util.Objects.hash;
5151

5252
/**
53-
* The utilities class for {@link MethodHandle}
53+
* Utility class for working with {@link MethodHandle}.
54+
* <p>
55+
* This class provides helper methods to simplify the usage of the {@link MethodHandles} API,
56+
* including creating lookups, finding methods, and handling invocation failures.
57+
* </p>
58+
*
59+
* <h3>Example Usage</h3>
60+
* <pre>{@code
61+
* // Example 1: Find a virtual method handle
62+
* MethodHandle mh = MethodHandleUtils.findVirtual(String.class, "length", int.class);
63+
* int length = (int) mh.invokeExact("Hello");
64+
* System.out.println(length); // Output: 5
65+
*
66+
* // Example 2: Find a static method handle
67+
* MethodHandle mh = MethodHandleUtils.findStatic(Math.class, "abs", double.class);
68+
* double abs = (double) mh.invokeExact(-42.0);
69+
* System.out.println(abs); // Output: 42.0
70+
*
71+
* // Example 3: Handle invokeExact failure
72+
* try {
73+
* MethodHandle mh = MethodHandleUtils.findVirtual(Object.class, "nonExistentMethod", void.class);
74+
* mh.invokeExact();
75+
* } catch (Throwable e) {
76+
* MethodHandleUtils.handleInvokeExactFailure(e, mh);
77+
* }
78+
* }</pre>
5479
*
5580
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
81+
* @see MethodHandles
82+
* @see MethodHandle
5683
* @since 1.0.0
5784
*/
5885
public abstract class MethodHandleUtils implements Utils {

0 commit comments

Comments
 (0)