Class ClassInjector.UsingLookup

java.lang.Object
net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
net.bytebuddy.dynamic.loading.ClassInjector.UsingLookup
All Implemented Interfaces:
ClassInjector
Enclosing interface:
ClassInjector

@Enhance public static class ClassInjector.UsingLookup extends ClassInjector.AbstractBase

A class injector that uses a java.lang.invoke.MethodHandles$Lookup object for defining a class.

Important: This functionality is only available starting from Java 9.

  • Field Details

    • METHOD_HANDLES

      private static final ClassInjector.UsingLookup.MethodHandles METHOD_HANDLES
      The dispatcher to interacting with instances of java.lang.invoke.MethodHandles.
    • METHOD_HANDLES_LOOKUP

      private static final ClassInjector.UsingLookup.MethodHandles.Lookup METHOD_HANDLES_LOOKUP
      The dispatcher to interacting with java.lang.invoke.MethodHandles$Lookup.
    • PACKAGE_LOOKUP

      private static final int PACKAGE_LOOKUP
      Indicates a lookup instance's package lookup mode.
      See Also:
    • lookup

      private final Object lookup
      The java.lang.invoke.MethodHandles$Lookup to use.
  • Constructor Details

    • UsingLookup

      protected UsingLookup(Object lookup)
      Creates a new class injector using a lookup instance.
      Parameters:
      lookup - The java.lang.invoke.MethodHandles$Lookup instance to use.
  • Method Details

    • doPrivileged

      @Enhance private static <T> T doPrivileged(PrivilegedAction<T> action)
      A proxy for java.security.AccessController#doPrivileged that is activated if available.
      Type Parameters:
      T - The type of the action's resolved value.
      Parameters:
      action - The action to execute from a privileged context.
      Returns:
      The action's resolved value.
    • of

      public static ClassInjector.UsingLookup of(Object lookup)
      Creates class injector that defines a class using a method handle lookup.
      Parameters:
      lookup - The java.lang.invoke.MethodHandles$Lookup instance to use.
      Returns:
      An appropriate class injector.
    • lookupType

      public Class<?> lookupType()
      Returns the lookup type this injector is based upon.
      Returns:
      The lookup type.
    • in

      public ClassInjector.UsingLookup in(Class<?> type)
      Resolves this injector to use the supplied type's scope.
      Parameters:
      type - The type to resolve the access scope for.
      Returns:
      An new injector with the specified scope.
    • isAlive

      public boolean isAlive()
      Indicates if this class injector is available on the current VM.
      Returns:
      true if this injector is available on the current VM.
    • injectRaw

      public Map<String,Class<?>> injectRaw(Map<? extends String,byte[]> types)
      Injects the given types into the represented class loader using a mapping from name to binary representation.
      Parameters:
      types - The types to load via injection.
      Returns:
      The loaded types that were passed as arguments.
    • isAvailable

      public static boolean isAvailable()
      Checks if the current VM is capable of defining classes using a method handle lookup.
      Returns:
      true if the current VM is capable of defining classes using a lookup.