In place of:
if (eventClass.equals(ChatButton.class)) {
newEvent = new ChatButton();
/* ... */
} else if (eventClass.equals(NUISkinEditorButton.class)) {
newEvent = new NUISkinEditorButton();
} else {
logger.error("ERROR!!! Event not Identified: " + originalEvent.toString());
}
You can use:
try {
return originalEvent.getClass()
.getConstructor()
.newInstance();
} catch (NoSuchMethodException
| IllegalAccessException
| InvocationTargetException
| InstantiationException
exception) {
logger.error("ERROR!!! Event not Identified: " + originalEvent.toString());
}
return null;