< prev index next > src/java.base/share/classes/java/lang/ScopedValue.java
Print this page
/**
* Returns the value of this scoped value if bound in the current thread, otherwise
* returns {@code other}.
*
! * @param other the value to return if not bound, can be {@code null}
* @return the value of the scoped value if bound, otherwise {@code other}
*/
public T orElse(T other) {
Object obj = findBinding();
if (obj != Snapshot.NIL) {
@SuppressWarnings("unchecked")
T value = (T) obj;
return value;
/**
* Returns the value of this scoped value if bound in the current thread, otherwise
* returns {@code other}.
*
! * @param other the value to return if not bound
* @return the value of the scoped value if bound, otherwise {@code other}
*/
public T orElse(T other) {
+ Objects.requireNonNull(other);
Object obj = findBinding();
if (obj != Snapshot.NIL) {
@SuppressWarnings("unchecked")
T value = (T) obj;
return value;
< prev index next >