This commit is contained in:
lxy
2020-09-07 22:11:29 +08:00
parent f848c57e39
commit 8d22d5e830
2 changed files with 12 additions and 1 deletions

View File

@@ -9,6 +9,9 @@ public class EventType<T> {
public final TypeToken<T> typeToken;
private final Consumer<T> consumer;
private final static TypeToken<String> stringToken = new TypeToken<>() {
};
private EventType(String topic, TypeToken<T> typeToken, Consumer<T> consumer) {
this.topic = topic;
this.typeToken = typeToken;
@@ -19,6 +22,10 @@ public class EventType<T> {
return new EventType<>(topic, typeToken, consumer);
}
public static EventType of(String topic, Consumer<String> consumer) {
return new EventType(topic, stringToken, consumer);
}
public void accept(T t) {
consumer.accept(t);
}