Class ClassCopyProvider<T>

java.lang.Object
net.imglib2.loops.ClassCopyProvider<T>

public class ClassCopyProvider<T> extends Object
Helper to create multiple copies of a class.

The copies of the class have individual copies of the byte code. The JIT compiler optimizes the class copies individually, which can increase performance.

  • Field Details

  • Constructor Details

    • ClassCopyProvider

      public ClassCopyProvider(Class<? extends T> clazz, Class<T> interfaceOfClazz, Class<?>... constructorSignature)
      Create a ClassCopyProvider to make copy a a given class.
      Parameters:
      clazz - Class to be copied.
      interfaceOfClazz - Interface that's implemented by the clazz. A class copies can only be used through this interface.
      constructorSignature - Constructor signature to be used when creating a new instance with newInstanceForKey(Object, Object...)
  • Method Details

    • assumeConstructorSignature

      private static Class<?>[] assumeConstructorSignature(Class<?> clazz)
    • hasDefaultConstructor

      private static boolean hasDefaultConstructor(Class<?> clazz)
    • classForKey

      private Class<? extends T> classForKey(Object key)
    • matches

      public boolean matches(Object... parameters)
      Returns true if the given list of objects, matches the constructor signature provided to ClassCopyProvider(Class, Class, Class[]).
    • newInstanceForKey

      public T newInstanceForKey(Object key, Object... parameters)
      Returns an instance of a copy of the original class, that has been provided to the constructor.

      Note: The returned object isn't an instance of the original class. Class.isInstance(Object) and "instanceof" will return false. And ClassCastException might occur if this is ignored.

      The returned instance has a copy of the byte code of the original class. This byte code is independently optimised by the JIT compiler. The JIT compiler will optimise the byte code, if it's only used in a specific use case. If used wisely a performance increase is the consequence.

      Parameters:
      key - Instances created with the same key, share their byte code.
      parameters - Parameters that are passed to the constructor.