Package emissary.util

Class ConstructorLookupCache


  • public final class ConstructorLookupCache
    extends Object
    This implements a simple caching mechanism for Constructor lookups. For example if the same class constructor is looked up repeatedly, using this cache may be able to avoid a lot of JVM reflection overhead.

    Note that the cache implementation may have a small capacity and/or be thread-specific, so storing something in the cache does not guarantee that it will be indefinitely cached or that the cached value will be visible to other threads.

    • Method Detail

      • get

        @Nullable
        public static Constructor<?> get​(Class<?> clazz,
                                         Class<?>[] argTypes)
        Look for a constructor in the cache.
        Parameters:
        clazz - The class to be constructed.
        argTypes - The argument types that the caller intends to pass to the constructor.
        Returns:
        If a matching constructor is in the cache, return it. Otherwise null.
      • put

        public static void put​(Class<?> clazz,
                               Class<?>[] argTypes,
                               Constructor<?> constructor)
        Store a constructor lookup in the cache.
        Parameters:
        clazz - The class to be constructed.
        argTypes - The argument types that the caller intends to pass to the constructor.
        constructor - A constructor for clazz that can accept the argument types specified in argTypes.
      • lookup

        public static Constructor<?> lookup​(Class<?> clazz,
                                            Class<?>[] argTypes)
        Look for a constructor for the given class type which can accept the given argument types.
        Parameters:
        clazz - The class to be constructed.
        argTypes - The argument types that the caller intends to pass to the constructor.
        Returns:
        A matching constructor for the specified class, or null if no such constructor was found.
      • unload

        public static void unload()
        Destroy the ThreadLocal cache object