Map<Class<? extends Packet>, PacketHandler> packetHandlers = new HashMap<>();
// create a PacketHandler instance for every Packet class
for (Class<? extends PacketHandler> packetHandlerClass : packetHandlerClasses) {
// Create a new instance of the PacketHandler
PacketHandler packetHandlerInstance = packetHandlerClass.newInstance();
// Check what Packet class this PacketHandler handles
Class<? extends Packet> packetClass = packetHandlerInstance.getPacketClass();
LOGGER.info("\"{}\" handles Packet class: {}", packetHandlerClass, packetClass);
// Make sure that there no PacketHandler that handles this Packet class yet
if (packetHandlers.containsKey(packetClass)) {
throw new IllegalStateException("Found a second PacketHandler (" + packetHandlerClass + ") that handles Packet class \"" + packetClass + "\"");