Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingReflection
- java.lang.Object
-
- net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection
-
- All Implemented Interfaces:
ClassInjector
- Enclosing interface:
- ClassInjector
public static class ClassInjector.UsingReflection extends java.lang.Object implements ClassInjector
A class injector that uses reflective method calls.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
ClassInjector.UsingReflection.Dispatcher
A dispatcher for accessing aClassLoader
reflectively.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ClassInjector.UsingInstrumentation, ClassInjector.UsingLookup, ClassInjector.UsingReflection, ClassInjector.UsingUnsafe
-
-
Field Summary
-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES
-
-
Constructor Summary
Constructors Constructor Description UsingReflection(java.lang.ClassLoader classLoader)
Creates a new injector for the givenClassLoader
and a defaultProtectionDomain
and a trivialPackageDefinitionStrategy
which does not trigger an error when discovering existent classes.UsingReflection(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)
Creates a new injector for the givenClassLoader
and a defaultPackageDefinitionStrategy
where the injection of existent classes does not trigger an error.UsingReflection(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting)
Creates a new injector for the givenClassLoader
andProtectionDomain
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<TypeDescription,java.lang.Class<?>>
inject(java.util.Map<? extends TypeDescription,byte[]> types)
Injects the given types into the represented class loader.static boolean
isAvailable()
Indicates if this class injection is available on the current VM.static ClassInjector
ofSystemClassLoader()
Creates a class injector for the system class loader.
-
-
-
Constructor Detail
-
UsingReflection
public UsingReflection(java.lang.ClassLoader classLoader)
Creates a new injector for the givenClassLoader
and a defaultProtectionDomain
and a trivialPackageDefinitionStrategy
which does not trigger an error when discovering existent classes.- Parameters:
classLoader
- TheClassLoader
into which new class definitions are to be injected. Must not be the bootstrap loader.
-
UsingReflection
public UsingReflection(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)
Creates a new injector for the givenClassLoader
and a defaultPackageDefinitionStrategy
where the injection of existent classes does not trigger an error.- Parameters:
classLoader
- TheClassLoader
into which new class definitions are to be injected. Must not be the bootstrap loader.protectionDomain
- The protection domain to apply during class definition.
-
UsingReflection
public UsingReflection(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting)
Creates a new injector for the givenClassLoader
andProtectionDomain
.- Parameters:
classLoader
- TheClassLoader
into which new class definitions are to be injected.Must not be the bootstrap loader.protectionDomain
- The protection domain to apply during class definition.packageDefinitionStrategy
- The package definer to be queried for package definitions.forbidExisting
- Determines if an exception should be thrown when attempting to load a type that already exists.
-
-
Method Detail
-
isAvailable
public static boolean isAvailable()
Indicates if this class injection is available on the current VM.- Returns:
true
if this class injection is available.
-
ofSystemClassLoader
public static ClassInjector ofSystemClassLoader()
Creates a class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-
inject
public java.util.Map<TypeDescription,java.lang.Class<?>> inject(java.util.Map<? extends TypeDescription,byte[]> types)
Description copied from interface:ClassInjector
Injects the given types into the represented class loader.- Specified by:
inject
in interfaceClassInjector
- Parameters:
types
- The types to load via injection.- Returns:
- The loaded types that were passed as arguments.
-
-