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.
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 TypeMethodDescription<T> TcreateWrapper(@NonNull Class<T> targetType, @NonNull Supplier<T> supplier) Creates a delegating wrapper of the given type using the providedSupplierfor its backend.static voidverifyTargetType(@NonNull Class<?> targetType) Verifies the target type is valid as a target type forwrapper 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 providedSupplierfor its backend.- Type Parameters:
T- type of implemented wrapper- Parameters:
targetType- type of implemented wrappersupplier- supplier to handle access to the underlying object- Returns:
- created delegating wrapper for the given supplier
- Throws:
IllegalArgumentException- iftargetTypecannot be directly implemented or inherited, i.e. if it isprivateor it is not an interface and isfinalor does not contain an empty non-privateconstructor,verifyTargetType(Class)should be used for this verification- API note
- if the original type declares fields or its non-
publicmethods 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
Verifies the target type is valid as a target type forwrapper creation.- Parameters:
targetType- target type ofwrapper creationwhich should be verified against method's contract- Throws:
IllegalArgumentException- iftargetTypeis not a valid type forwrapper creation
-