Skip to content

io microsphere invoke MethodHandlesLookupUtils

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

MethodHandlesLookupUtils

Type: Class | Module: microsphere-java-core | Package: io.microsphere.invoke | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/invoke/MethodHandlesLookupUtils.java

Overview

Utilities class providing convenient methods for working with MethodHandles.Lookup.

This class offers various static methods to simplify the process of obtaining and using method handles, particularly for public virtual and static methods. It serves as a central utility to reduce boilerplate code when dealing with reflection and method handle lookup.

Example Usage

- Finding a public virtual method:
    <pre>`MethodHandle mh = MethodHandlesLookupUtils.findPublicVirtual(String.class, "toString");

`

- Finding a public static method:
    <pre>`MethodHandle mh = MethodHandlesLookupUtils.findPublicStatic(Math.class, "abs", int.class);

`

Declaration

public abstract class MethodHandlesLookupUtils implements Utils

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Example 1

MethodHandle mh = MethodHandlesLookupUtils.findPublicVirtual(String.class, "toString");

Example 2

MethodHandle mh = MethodHandlesLookupUtils.findPublicStatic(Math.class, "abs", int.class);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.invoke.MethodHandlesLookupUtils;

API Reference

Public Methods

Method Description
findPublicVirtual MethodHandle for Not-Found
findPublicStatic The convenient method to find MethodHandles.Lookup#findStatic(Class, String, MethodType) for public static method

Method Details

findPublicVirtual

public static MethodHandle findPublicVirtual(Class<?> requestedClass, String methodName, Class... parameterTypes)

MethodHandle for Not-Found / public static final MethodHandle NOT_FOUND_METHOD_HANDLE = null;

/** The MethodHandles.Lookup for MethodHandles#publicLookup() / public static final MethodHandles.Lookup PUBLIC_LOOKUP = publicLookup();

/** The convenient method to find MethodHandles.Lookup#findVirtual(Class, String, MethodType) for public method

findPublicStatic

public static MethodHandle findPublicStatic(Class<?> requestedClass, String methodName, Class... parameterTypes)

The convenient method to find MethodHandles.Lookup#findStatic(Class, String, MethodType) for public static method

See Also

  • MethodHandles
  • MethodHandle

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally