Class 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 Detail

      • PACKAGE_LOOKUP

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

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

      • UsingLookup

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

      • of

        public static ClassInjector.UsingLookup of​(java.lang.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 java.lang.Class<?> lookupType()
        Returns the lookup type this injector is based upon.
        Returns:
        The lookup type.
      • in

        public ClassInjector.UsingLookup in​(java.lang.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 java.util.Map<java.lang.String,​java.lang.Class<?>> injectRaw​(java.util.Map<? extends java.lang.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.