MethodHandles
MethodHandles is a Java API introduced in Java 7 that provides a way to invoke methods indirectly. It offers a more flexible and powerful alternative to traditional reflection, allowing for dynamic method invocation with better performance and type safety. The core concept revolves around a lookup object and a method handle. A lookup object is used to find a method handle corresponding to a specific method. Once a method handle is obtained, it can be invoked directly, similar to calling a regular method.
Unlike reflection, which provides access to method metadata, method handles provide a direct reference to executable
The API is organized around the java.lang.invoke package, featuring classes like MethodHandles, MethodHandle, MethodType, and Lookup.
MethodHandles are particularly useful in scenarios requiring advanced dynamic behavior, such as implementing dynamically typed languages