Class ConstructorCache


  • @SdkInternalApi
    public final class ConstructorCache
    extends Object
    A cache that stores classes and exposes a method to retrieve its zero-argument constructor.

    This cache stores weak references to loaded classes, allowing them to be garbage collected at any point.

    Classes are loaded by first attempting to load it via the thread context ClassLoader (or system ClassLoader if the calling thread does not have one). If that fails, it will attempt using the ClassLoader that loaded ClassLoaderHelper.

    If a class or its zero-argument constructor cannot be found, an empty result is returned.

    See Also:
    ClassLoaderHelper.loadClass(String, boolean, Class[])
    • Constructor Detail

      • ConstructorCache

        public ConstructorCache()
    • Method Detail

      • getConstructor

        public Optional<Constructor<?>> getConstructor​(String className)
        Retrieve the zero-argument constructor for the given class name. Returns an empty result if no such constructor is found.