Class ClassFileLocator.ForModule.WeaklyReferenced

java.lang.Object
java.lang.ref.Reference<Object>
java.lang.ref.WeakReference<Object>
net.bytebuddy.dynamic.ClassFileLocator.ForModule.WeaklyReferenced
All Implemented Interfaces:
Closeable, AutoCloseable, ClassFileLocator
Enclosing class:
ClassFileLocator.ForModule

public static class ClassFileLocator.ForModule.WeaklyReferenced extends WeakReference<Object> implements ClassFileLocator

A class file locator for a Java module that only references this module weakly. If a module was garbage collected, this class file locator only returns unresolved resolutions.

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.

  • Field Details

    • hashCode

      private final int hashCode
      The represented module's hash code.
  • Constructor Details

    • WeaklyReferenced

      protected WeaklyReferenced(Object module)
      Creates a class file locator for a Java module that is weakly referenced.
      Parameters:
      module - The raw Java module to represent.
  • Method Details

    • of

      public static ClassFileLocator of(JavaModule module)
      Creates a class file locator for a Java module where the module is referenced weakly. If the module is not named, the module's class loader is represented instead. Module's of the boot layer are not referenced weakly.
      Parameters:
      module - The Java module to represent.
      Returns:
      A suitable class file locator.
    • locate

      public ClassFileLocator.Resolution locate(String name) throws IOException
      Locates the class file for a given type and returns the binary data of the class file.
      Specified by:
      locate in interface ClassFileLocator
      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 interface AutoCloseable
      Specified by:
      close in interface Closeable
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@MaybeNull Object other)
      Overrides:
      equals in class Object