spring-framework / org.springframework.beans.factory / ObjectProvider / getIfAvailable

getIfAvailable

@Nullable abstract fun getIfAvailable(): T

Return an instance (possibly shared or independent) of the object managed by this factory.

Exceptions

BeansException - in case of creation errors

Return
an instance of the bean, or null if not available

See Also
#getObject()

open fun getIfAvailable(defaultSupplier: Supplier<T>): T

Return an instance (possibly shared or independent) of the object managed by this factory.

Parameters

defaultSupplier - a callback for supplying a default object if none is present in the factory

Exceptions

BeansException - in case of creation errors

Return
an instance of the bean, or the supplied default object if no such bean is available

Since
5.0

See Also
#getIfAvailable()