Use computeIfAbsent in EventBus (#2138)

This commit is contained in:
Glavo 2023-02-19 13:25:20 +08:00 committed by GitHub
parent ed0a4c8cf4
commit 6f70da51f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,8 +31,7 @@ public final class EventBus {
@SuppressWarnings("unchecked")
public <T extends Event> EventManager<T> channel(Class<T> clazz) {
events.putIfAbsent(clazz, new EventManager<>());
return (EventManager<T>) events.get(clazz);
return (EventManager<T>) events.computeIfAbsent(clazz, ignored -> new EventManager<>());
}
@SuppressWarnings("unchecked")