public final class ScopeKey<T> extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> ScopeKey<T> |
allocate() |
T |
get() |
boolean |
set(T value) |
static ScopeKey<Boolean> |
withDefaultValue(boolean defaultValue) |
static ScopeKey<Double> |
withDefaultValue(double defaultValue) |
static ScopeKey<Integer> |
withDefaultValue(int defaultValue) |
static ScopeKey<Long> |
withDefaultValue(long defaultValue) |
static ScopeKey<String> |
withDefaultValue(String defaultValue) |
static <T extends Enum<T>> |
withDefaultValue(T defaultValue) |
static <T> ScopeKey<T> |
withInitializer(Supplier<T> initializer) |
@Nonnull public static <T extends Enum<T>> ScopeKey<T> withDefaultValue(T defaultValue)
@Nonnull public static <T> ScopeKey<T> withInitializer(Supplier<T> initializer)
initializer - 初始化ScopeKey(仅在Scope有效时)
等效代码:(调用 get() 时)
T obj = SCOPE_KEY.get();
if (obj == null) {
obj = initializer.get();
SCOPE_KEY.set(obj);
}
return obj;
public T get()
public boolean set(T value)
true if in a scope and set success.Copyright © 2019. All rights reserved.