Class MapClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

@AvailableSince("0.0.50") public class MapClassLoader extends URLClassLoader
A ClassLoader that defines a fixed set of classes provided at construction time from an in-memory mapping of fully-qualified binary name to JVM bytecode.

Every entry in the classDefs map passed to the constructor is eagerly defined in this loader via ClassLoader.defineClass(String, byte[], int, int). Subsequent lookups for any of those classes through ClassLoader.loadClass(String) resolve to the Class defined by this loader; any other name is delegated to the parent loader using the standard parent-first model inherited from URLClassLoader.

This loader exposes no URLs — only the classes supplied at construction are available directly from it.

See Also:
  • Constructor Details

    • MapClassLoader

      public MapClassLoader(ClassLoader parent, Map<String,ImmutableByteArrayList> classDefs)
      Constructs a new MapClassLoader that eagerly defines every entry of classDefs as a class loaded by this loader.
      Parameters:
      parent - parent class loader for delegation; may be null to delegate to the bootstrap class loader (see ClassLoader(ClassLoader))
      classDefs - map of fully-qualified binary name (e.g. "com.example.Foo") to the bytecode for that class. The map is consumed at construction; later modifications to the supplied map have no effect on this loader.
      Throws:
      ClassFormatError - if a bytecode entry is not a well-formed class file
      NoClassDefFoundError - if a key in classDefs does not match the binary name encoded inside the corresponding bytecode
      See Also: