9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

contextholder添加get方法

This commit is contained in:
Catnies
2025-12-14 06:43:06 +08:00
parent 8013feddd9
commit b5f4bdda48

View File

@@ -63,6 +63,11 @@ public class ContextHolder {
return this;
}
@SuppressWarnings("unchecked")
public <T> T get(ContextKey<T> parameter) {
return (T) Optional.ofNullable(this.params.get(parameter)).map(Supplier::get).orElse(null);
}
@SuppressWarnings("unchecked")
public <T> T getOrThrow(ContextKey<T> parameter) {
Supplier<T> object = (Supplier<T>) this.params.get(parameter);