dimanche 16 août 2020

Java Reflection to Instantiate Generics at Runtime

Basically how could I get functionality like this to work.

Reflections reflections = new Reflections("com.mycompany");    
Set<Class<? extends BlockEvent>> classes = reflections.getSubTypesOf(BlockEvent.class);
for (Class<? extends BlockEvent> clazz : classes) {
    getServer().getPluginManager().registerEvents(new BlockEventListener<clazz>(), this);
}

I want to register a listener for all event types that extend BlockEvent. Obviously clazz is not a type and cannot be used as such.





Aucun commentaire:

Enregistrer un commentaire