All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cucumber.needle.CreateInstanceByDefaultConstructor Maven / Gradle / Ivy

There is a newer version: 6.11.0
Show newest version
package io.cucumber.needle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Instantiates new java object by default constructor
 */
enum CreateInstanceByDefaultConstructor {
    /**
     * Singleton
     */
    INSTANCE;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    final  T apply(final Class type) {
        try {
            final T newInstance = type.getConstructor().newInstance();
            logger.debug("newInstance by DefaultConstructor: {}", newInstance);
            return newInstance;
        } catch (final Exception e) {
            throw new IllegalStateException("Can not instantiate Instance by Default Constructor.", e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy