Class MethodHandlesExtensions

java.lang.Object
org.lanternpowered.lmbda.MethodHandlesExtensions

public final class MethodHandlesExtensions
extends java.lang.Object
A class with extension methods related to MethodHandles.
  • Method Summary

    Modifier and Type Method Description
    static @NonNull java.lang.Class<?> defineClass​(@NonNull java.lang.invoke.MethodHandles.Lookup lookup, byte @NonNull [] byteCode)
    Defines a Class to the same ClassLoader and in the same runtime package and ProtectionDomain as the MethodHandles.Lookup's lookup class.
    static @NonNull java.lang.invoke.MethodHandles.Lookup privateLookupIn​(@NonNull java.lang.Class<?> targetClass, @NonNull java.lang.invoke.MethodHandles.Lookup lookup)
    Gets a lookup object with full capabilities to emulate all supported bytecode behaviors, including private access, on a target class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • privateLookupIn

      public static @NonNull java.lang.invoke.MethodHandles.Lookup privateLookupIn​(@NonNull java.lang.Class<?> targetClass, @NonNull java.lang.invoke.MethodHandles.Lookup lookup) throws java.lang.IllegalAccessException
      Gets a lookup object with full capabilities to emulate all supported bytecode behaviors, including private access, on a target class.

      If there is a security manager, its checkPermission method is called to check ReflectPermission("suppressAccessChecks").

      When using Java 9+, see https://docs.oracle.com/javase/9/docs/api/java/lang/invoke/MethodHandles.html#privateLookupIn-java.lang.Class-java.lang.invoke.MethodHandles.Lookup-

      Parameters:
      targetClass - The target class for which private access should be acquired
      lookup - The caller lookup object
      Returns:
      A lookup object for the target class, with private access
      Throws:
      java.lang.IllegalAccessException - If the lookup doesn't have private access to the target class
    • defineClass

      public static @NonNull java.lang.Class<?> defineClass​(@NonNull java.lang.invoke.MethodHandles.Lookup lookup, byte @NonNull [] byteCode) throws java.lang.IllegalAccessException
      Defines a Class to the same ClassLoader and in the same runtime package and ProtectionDomain as the MethodHandles.Lookup's lookup class.
      Parameters:
      lookup - The lookup of which the target class will be used to define the class in
      byteCode - The byte code of the class to define
      Returns:
      The defined class
      Throws:
      java.lang.IllegalAccessException - If the lookup doesn't have package private access to the target package