ReflectionUtils (JNA API)
Description: declaration: package: com.sun.jna.internal, class: ReflectionUtils

Package com.sun.jna.internal

# Class ReflectionUtils

java.lang.Object
com.sun.jna.internal.ReflectionUtils

public class ReflectionUtils extends Object
Helper class to invoke default method reflectively.

This class is intented to be used only be JNA itself.

This implementation is inspired by: Correct Reflective Access to Interface Default Methods in Java 8, 9, 10

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ReflectionUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Object`
  `getMethodHandle(Method method)`
  Retrieve the method handle, that can be used to invoke the provided method.
  `static Object`
  `invokeDefaultMethod(Object target, Object methodHandle, Object... args)`
  Invokes a default method reflectively.
  `static boolean`
  `isDefault(Method method)`
  Check if the supplied method object represents a default method.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ReflectionUtils

    public ReflectionUtils()

- ## Method Details

  - ### isDefault

    public static boolean isDefault(Method method)
    Check if the supplied method object represents a default method.

    This is the reflective equivalent of `method.isDefault()`.

    Parameters:
      `method` -
    Returns:
      true if JVM supports default methods and `method` is a default method

  - ### getMethodHandle

    public static Object getMethodHandle(Method method) throws Exception
    Retrieve the method handle, that can be used to invoke the provided method. It is only intended to be used to call default methods on interfaces.
    Parameters:
      `method` -
    Returns:
      method handle that can be used to invoke the supplied method
    Throws:
      `Exception`

  - ### invokeDefaultMethod

    public static Object invokeDefaultMethod(Object target, Object methodHandle, Object... args) throws Throwable
    Invokes a default method reflectively. The method must be called with the method handle for a default method on an interfaces.
    Parameters:
      `target` - object to invoke the supplied method handle on
      `methodHandle` - retrieved via `getMethodHandle(java.lang.reflect.Method)`
      `args` -
    Returns:
      result of the invokation
    Throws:
      `Throwable`