@SuppressWarnings("unchecked")
<T extends Component> T newInstance(Class<T> componentClass, boolean constructorHasWorldParameter) {
try {
if (constructorHasWorldParameter) {
Constructor constructor = ClassReflection.getConstructor(componentClass, World.class);
return (T) constructor.newInstance(world);
} else {
return ClassReflection.newInstance(componentClass);
}
} catch (ReflectionException e) {
throw new InvalidComponentException(componentClass, "Unable to instantiate component.", e);