Interface BeanReference<T>
-
- Type Parameters:
T- The type of the referenced bean.
public interface BeanReference<T>A reference to a bean, allowing the retrieval of that bean whenpassedaBeanResolver.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <U> BeanReference<? extends U>asSubTypeOf(Class<U> expectedType)Cast this reference into a reference whoseresolve(BeanResolver)method is is guaranteed to either fail or return an instance of the given type.static <T> BeanReference<T>of(Class<T> type)Create aBeanReferencereferencing a bean by its type only.static <T> BeanReference<T>of(Class<T> type, String name)Create aBeanReferencereferencing a bean by type and name.static <T> BeanReference<T>of(Class<T> type, String name, BeanRetrieval retrieval)Create aBeanReferencereferencing a bean by type and name.static <T> BeanReference<T>of(Class<T> type, BeanRetrieval retrieval)Create aBeanReferencereferencing a bean by its type only.static <T> BeanReference<T>ofInstance(T instance)Create aBeanReferencereferencing a bean instance directly.static <T> BeanReference<T>parse(Class<T> expectedType, String value)static BeanReference<?>parse(String value)BeanHolder<T>resolve(BeanResolver beanResolver)Resolve this reference into a bean using the given resolver.
-
-
-
Method Detail
-
resolve
BeanHolder<T> resolve(BeanResolver beanResolver)
Resolve this reference into a bean using the given resolver.- Parameters:
beanResolver- A resolver to resolve this reference with.- Returns:
- The bean instance.
-
asSubTypeOf
default <U> BeanReference<? extends U> asSubTypeOf(Class<U> expectedType)
Cast this reference into a reference whoseresolve(BeanResolver)method is is guaranteed to either fail or return an instance of the given type.- Type Parameters:
U- The expected bean type.- Parameters:
expectedType- The expected bean type.- Returns:
- A bean reference.
- Throws:
ClassCastException- If this reference is certain to never return an instance of the given type.
-
of
static <T> BeanReference<T> of(Class<T> type)
Create aBeanReferencereferencing a bean by its type only.- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not be null.- Returns:
- The corresponding
BeanReference.
-
of
static <T> BeanReference<T> of(Class<T> type, BeanRetrieval retrieval)
Create aBeanReferencereferencing a bean by its type only.- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not be null.retrieval- How to retrieve the bean. SeeBeanRetrieval.- Returns:
- The corresponding
BeanReference.
-
of
static <T> BeanReference<T> of(Class<T> type, String name)
Create aBeanReferencereferencing a bean by type and name.- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not be null.name- The bean name. May be null or empty.- Returns:
- The corresponding
BeanReference.
-
of
static <T> BeanReference<T> of(Class<T> type, String name, BeanRetrieval retrieval)
Create aBeanReferencereferencing a bean by type and name.- Type Parameters:
T- The bean type.- Parameters:
type- The bean type. Must not be null.name- The bean name. May be null or empty.retrieval- How to retrieve the bean. SeeBeanRetrieval.- Returns:
- The corresponding
BeanReference.
-
ofInstance
static <T> BeanReference<T> ofInstance(T instance)
Create aBeanReferencereferencing a bean instance directly.- Type Parameters:
T- The bean type.- Parameters:
instance- The bean instance. Must not be null.- Returns:
- The corresponding
BeanReference.
-
parse
static BeanReference<?> parse(String value)
-
parse
static <T> BeanReference<T> parse(Class<T> expectedType, String value)
-
-