public Annotator getAnnotator(Class<? extends Annotator> clazz) {

        if (!Annotator.class.isAssignableFrom(clazz)) {
            throw new IllegalArgumentException("The class name given as a custom annotator (" + clazz.getName() + ") does not refer to a class that implements " + Annotator.class.getName());
        }

        try {
            try {
                Constructor<? extends Annotator> constructor = clazz.getConstructor(GenerationConfig.class);
                return constructor.newInstance(generationConfig);
            } catch (NoSuchMethodException e) {
                return clazz.newInstance();
            }
        } catch (InvocationTargetException | InstantiationException e) {
            throw new IllegalArgumentException("Failed to create a custom annotator from the given class. An exception was thrown on trying to create a new instance.", e.getCause());
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Failed to create a custom annotator from the given class. It appears that we do not have access to this class - is both the class and its no-arg constructor marked public?", e);
        }

    }
public Annotator getAnnotator ( Class < ? extends Annotator > clazz ) { if ( ! Annotator . class . isAssignableFrom ( clazz ) ) { throw new IllegalArgumentException ( "The class name given as a custom annotator (" + clazz . getName ( ) + ") does not refer to a class that implements " + Annotator . class . getName ( ) ) ; } try { try { Constructor < ? extends Annotator > constructor = clazz . getConstructor ( GenerationConfig . class ) ; return constructor . newInstance ( generationConfig ) ; } catch ( NoSuchMethodException e ) { return clazz . newInstance ( ) ; } } catch ( InvocationTargetException | InstantiationException e ) { throw new IllegalArgumentException ( "Failed to create a custom annotator from the given class. An exception was thrown on trying to create a new instance." , e . getCause ( ) ) ; } catch ( IllegalAccessException e ) { throw new IllegalArgumentException ( "Failed to create a custom annotator from the given class. It appears that we do not have access to this class - is both the class and its no-arg constructor marked public?" , e ) ; } }
Create a new custom {@link Annotator} from the given class.

@param clazz
A class implementing {@link Annotator}.
@return an instance of the given annotator type