Created
October 29, 2023 10:57
-
-
Save mskoroglu/f19d4d159ddae51480499b8088e00957 to your computer and use it in GitHub Desktop.
An example of reified generic types in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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