Interface DelegateFactory

All Known Implementing Classes:
AsmDelegateFactory, CachingGeneratingDelegateFactory, ProxyDelegateFactory
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface DelegateFactory

Factory capable of creating type-safe delegating wrappers.

A good use-case is wrapping Lazy so that the object becomes Lazy yet being of its original type

  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    createWrapper(@NonNull Class<T> targetType, @NonNull Supplier<T> supplier)
    Creates a delegating wrapper of the given type using the provided Supplier for its backend.
    static void
    verifyTargetType(@NonNull Class<?> targetType)
    Verifies the target type is valid as a target type for wrapper creation.
  • Method Details

    • createWrapper

      @NotNull <T> T createWrapper(@NonNull @NonNull Class<T> targetType, @NonNull @NonNull Supplier<T> supplier)
      Creates a delegating wrapper of the given type using the provided Supplier for its backend.
      Type Parameters:
      T - type of implemented wrapper
      Parameters:
      targetType - type of implemented wrapper
      supplier - supplier to handle access to the underlying object
      Returns:
      created delegating wrapper for the given supplier
      Throws:
      IllegalArgumentException - if targetType cannot be directly implemented or inherited, i.e. if it is private or it is not an interface and is final or does not contain an empty non-private constructor, verifyTargetType(Class) should be used for this verification
      API note
      if the original type declares fields or its non-public methods are visible to the owner of this object than access to them will lead to undefined behaviour and most probably will cause logical issues
    • verifyTargetType

      static void verifyTargetType(@NonNull @NonNull Class<?> targetType)
      Verifies the target type is valid as a target type for wrapper creation.
      Parameters:
      targetType - target type of wrapper creation which should be verified against method's contract
      Throws:
      IllegalArgumentException - if targetType is not a valid type for wrapper creation