Class MemoryClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class MemoryClassLoader extends URLClassLoader
An URLClassLoader that maintains an updatable cache of class files (as byte[] arrays) in memory from which classes may be loaded.

The internal cache of classes is initially empty. Binary class files may be added (or removed) via putClass(), and retrieved via getClass(). The byte[] arrays passed to and from these methods are copied to ensure immutability.

Classes defined by this loader are assigned URLs that look like memory:/com.example.MyClass.

This class is thread safe and parallel capable.

  • Field Details

  • Constructor Details

    • MemoryClassLoader

      public MemoryClassLoader()
      Default constructor.

      Uses the current thread's context loader as the parent loader.

    • MemoryClassLoader

      public MemoryClassLoader(ClassLoader parent)
      Constructor.
      Parameters:
      parent - parent class loader, possibly null
  • Method Details