Skip to content

Instantly share code, notes, and snippets.

@mskoroglu
Created October 29, 2023 10:57
Show Gist options
  • Save mskoroglu/f19d4d159ddae51480499b8088e00957 to your computer and use it in GitHub Desktop.
Save mskoroglu/f19d4d159ddae51480499b8088e00957 to your computer and use it in GitHub Desktop.
An example of reified generic types in Java
public abstract class EventHandler<E extends Event> {
@SafeVarargs
protected EventHandler(final E... reifiedTypeArray) {
if (reifiedTypeArray.length > 0) {
throw new IllegalArgumentException();
}
final var reifiedType = reifiedTypeArray.getClass().getComponentType();
EventBus.registerHandler((Class<? extends Event>) reifiedType, this);
}
public abstract void handle(E e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment