Klasse 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

  • Konstruktordetails

    • ReflectionUtils

      public ReflectionUtils()
  • Methodendetails

    • 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().

      Parameter:
      method -
      Gibt zurück:
      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.
      Parameter:
      method -
      Gibt zurück:
      method handle that can be used to invoke the supplied method
      Löst aus:
      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.
      Parameter:
      target - object to invoke the supplied method handle on
      methodHandle - retrieved via getMethodHandle(java.lang.reflect.Method)
      args -
      Gibt zurück:
      result of the invokation
      Löst aus:
      Throwable