File tree Expand file tree Collapse file tree
microsphere-java-core/src/main/java/io/microsphere/invoke Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050import 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 */
5885public abstract class MethodHandleUtils implements Utils {
You can’t perform that action at this time.
0 commit comments