Package net.bytebuddy.dynamic
Class ClassFileLocator.ForClassLoader.WeaklyReferenced
java.lang.Object
java.lang.ref.Reference<ClassLoader>
java.lang.ref.WeakReference<ClassLoader>
net.bytebuddy.dynamic.ClassFileLocator.ForClassLoader.WeaklyReferenced
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ClassFileLocator
- Enclosing class:
ClassFileLocator.ForClassLoader
public static class ClassFileLocator.ForClassLoader.WeaklyReferenced
extends WeakReference<ClassLoader>
implements ClassFileLocator
A class file locator that queries a class loader for binary representations of class files. The class loader is only weakly referenced.
Important: Even when calling Closeable.close()
on this class file locator, no underlying
class loader is closed if it implements the Closeable
interface as this is typically not intended.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.ClassFileLocator
ClassFileLocator.Compound, ClassFileLocator.Filtering, ClassFileLocator.ForClassLoader, ClassFileLocator.ForFolder, ClassFileLocator.ForInstrumentation, ClassFileLocator.ForJarFile, ClassFileLocator.ForModule, ClassFileLocator.ForModuleFile, ClassFileLocator.ForUrl, ClassFileLocator.NoOp, ClassFileLocator.PackageDiscriminating, ClassFileLocator.Resolution, ClassFileLocator.Simple
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
The represented class loader's hash code.Fields inherited from interface net.bytebuddy.dynamic.ClassFileLocator
CLASS_FILE_EXTENSION
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WeaklyReferenced
(ClassLoader classLoader) Creates a class file locator for a class loader that is weakly referenced. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
int
hashCode()
Locates the class file for a given type and returns the binary data of the class file.static ClassFileLocator
of
(ClassLoader classLoader) Creates a class file locator for a given class loader.Methods inherited from class java.lang.ref.Reference
clear, clone, enqueue, get, isEnqueued, reachabilityFence, refersTo
-
Field Details
-
hashCode
private final int hashCodeThe represented class loader's hash code.
-
-
Constructor Details
-
WeaklyReferenced
Creates a class file locator for a class loader that is weakly referenced.- Parameters:
classLoader
- The class loader to represent.
-
-
Method Details
-
of
Creates a class file locator for a given class loader. If the class loader is not the bootstrap class loader or the system class loader which cannot be collected, the class loader is only weakly referenced.- Parameters:
classLoader
- The class loader to be used. If this class loader represents the bootstrap class loader which is represented by thenull
value, this system class loader is used instead.- Returns:
- A corresponding source locator.
-
locate
Locates the class file for a given type and returns the binary data of the class file.- Specified by:
locate
in interfaceClassFileLocator
- Parameters:
name
- The name of the type to locate a class file representation for.- Returns:
- Any binary representation of the type which might be illegal.
- Throws:
IOException
- If reading a class file causes an error.
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
hashCode
public int hashCode() -
equals
-