类 BindResult<T>
- java.lang.Object
- org.springframework.boot.context.properties.bind.BindResult<T>
- 类型参数:
T
- the result type
public final class BindResult<T> extends Object
A container object to return the result of aBinder
bind operation. May contain either a successfully bound object or an empty result.- 从以下版本开始:
- 2.0.0
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 boolean
equals(Object obj)
T
get()
Return the object that was bound or throw aNoSuchElementException
if no value was bound.int
hashCode()
void
ifBound(Consumer<? super T> consumer)
Invoke the specified consumer with the bound value, or do nothing if no value has been bound.boolean
isBound()
Returnstrue
if a result was bound.<U> BindResult<U>
map(Function<? super T,? extends U> mapper)
Apply the provided mapping function to the bound value, or return an updated unbound result if no value has been bound.T
orElse(T other)
Return the object that was bound, orother
if no value has been bound.T
orElseCreate(Class<? extends T> type)
Return the object that was bound, or a new instance of the specified class if no value has been bound.T
orElseGet(Supplier<? extends T> other)
Return the object that was bound, or the result of invokingother
if no value has been bound.<X extends Throwable>
TorElseThrow(Supplier<? extends X> exceptionSupplier)
Return the object that was bound, or throw an exception to be created by the provided supplier if no value has been bound.
方法详细资料
get
public T get() throws NoSuchElementException
Return the object that was bound or throw aNoSuchElementException
if no value was bound.- 返回:
- the bound value (never
null
) - 抛出:
NoSuchElementException
- if no value was bound- 另请参阅:
isBound()
isBound
public boolean isBound()
Returnstrue
if a result was bound.- 返回:
- if a result was bound
ifBound
public void ifBound(Consumer<? super T> consumer)
Invoke the specified consumer with the bound value, or do nothing if no value has been bound.- 参数:
consumer
- block to execute if a value has been bound
map
public <U> BindResult<U> map(Function<? super T,? extends U> mapper)
Apply the provided mapping function to the bound value, or return an updated unbound result if no value has been bound.- 类型参数:
U
- the type of the result of the mapping function- 参数:
mapper
- a mapping function to apply to the bound value. The mapper will not be invoked if no value has been bound.- 返回:
- an
BindResult
describing the result of applying a mapping function to the value of thisBindResult
.
orElse
public T orElse(T other)
Return the object that was bound, orother
if no value has been bound.- 参数:
other
- the value to be returned if there is no bound value (may benull
)- 返回:
- the value, if bound, otherwise
other
orElseGet
public T orElseGet(Supplier<? extends T> other)
Return the object that was bound, or the result of invokingother
if no value has been bound.- 参数:
other
- aSupplier
of the value to be returned if there is no bound value- 返回:
- the value, if bound, otherwise the supplied
other
orElseCreate
public T orElseCreate(Class<? extends T> type)
Return the object that was bound, or a new instance of the specified class if no value has been bound.- 参数:
type
- the type to create if no value was bound- 返回:
- the value, if bound, otherwise a new instance of
type
orElseThrow
public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X extends Throwable
Return the object that was bound, or throw an exception to be created by the provided supplier if no value has been bound.- 类型参数:
X
- the type of the exception to be thrown- 参数:
exceptionSupplier
- the supplier which will return the exception to be thrown- 返回:
- the present value
- 抛出:
X
- if there is no value presentX extends Throwable